This has been on my mind for a week now and i can't seem to understand it.
i have this problem:
//1.Make an average of 3 numbers
//2.Display average with two decimals exactly
//3.Average must NOT be rounded
using namespace std;
double x, y ,z, average;
cin>> x >> y >> z;
average = (x+y+z)/3;
It's a matter of definition and specification. The division
(x+y+z)/3 is a floating-point one and
setprecision() obviously rounds the decimal digits, rather than truncates them. You may need to either choose another function (truncating, rather than rounding), or even partially employ a fixed-point logic. Eg if x, y and z are integers, you could use
((x+y+z)*100/3) / 100.0. (a quite common approach when 'amount' data are represented and processed).
OR (if x, y and z are floats):