i can't get cout
to display decimals (using eclipse c++ and mingw)
#include <iostream>
using namespace std;
int main() {
int a = 55, b = 60, c = 70;
double avgResult;
avgResult = ((a + b + c) / 3);
cout << avgResult; //should display 61.666666
return 0;
}
my output is 61 when I would expect it to be 61.666666.
I can get it to display the decimals using
cout << std::fixed << std::setprecision(2) << avrResult;
but I thought I didn't need to do that unless I wanted a specific decimal precision.
If I do something like
double value = 12.345;
cout << value;
it displays correctly so it leads me to believe that the above problem has to do with the use of int
values in my calculation of double avgResult
btw I am new to c++ and am just starting to learn