Feb 23, 2012 at 6:35am UTC
whitenite1 tell you.
you use float or float instead int
but use to declare a variable
e.g
float a=8,b=3;
cout<<a/b;
OR
cout<< 8.0/3.0;
Feb 23, 2012 at 10:31pm UTC
Well actually, my original problem was more like this. If I input 5 and 2, for example, it outputs 2.00.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
#include <iostream>
using namespace std;
int main(){
int a, b;
double avg;
cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision(2);
cin >> a >> b;
avg = static_cast <double >(a/b);
cout << avg;
return 0;
}
Last edited on Feb 23, 2012 at 10:34pm UTC
Feb 24, 2012 at 4:04am UTC
That's because you declared a and b as ints. They will always be whole numbers. Declare a and b as floats, and the program should work a LOT better.
Feb 24, 2012 at 4:19am UTC
I was asked for them to be ints