why does
print 2 not 2.98?Code:cout<<149/50;
Printable View
why does
print 2 not 2.98?Code:cout<<149/50;
because 149 and 50 are both integers, so the result of the division is an integer.
You have to use floating point types to get the right answer. Do 149.f/50.f instead.
cout << 149./50;
or
cout << 149.0/50;
or
cout << (float)149/50;
or
cout << (double)149/50;
will give you 2.98
(Anything that will tell the compiler to convert the result to a floating point type.)
cout<<float(149)/50;
*meep*
thanks whoever posted first :-p