I don't know how to display decimals. At the moment, the program shows integers. I need it to display numbers like 9.33 too.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
#include <iostream>
#include <iomanip>
#include <stdio.h>
usingnamespace std;
int main()
{
int x, y, z;
int M;
cin>>x>>y>>z;
M=(x+y+z)/3;
cout<<M;
return 0;
}
This (x+y+z)/3; is doing integer division, the result is an integer. Though you can assign the result to a variable of type double, that doesn't change the result
Instead, make sure at least one of the operands (in this case 3.0) is type double, in order to do floating-point division.
double M = (x+y+z)/3.0;
Edit: the suggestion by edge6768 is correct, but in my opinion, rather more complex than is needed here.