- Jan 7, 2002
- 9,448
- 1
- 76
I was doing my homework and it asked "how will this value look when it is ouput?" and things along that line. So I answered them all but was wrong with all the floats. I answered the following with 3.0 and when I put it in my test program I get 3.
What gives? I thought floats, by their nature, had a decimal point and trailing zero. Is it being coerced into an int because of it being an absolute value?
(All the libraries are included because I write many problems with this same program, and I don't want to keep changing it. In a real program I know it's extra overhead, but this is only for testing.)
TIA
What gives? I thought floats, by their nature, had a decimal point and trailing zero. Is it being coerced into an int because of it being an absolute value?
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <string>
using namespace std;
int main()
{
float x = sqrt(fabs(-4.0) + sqrt(25.0));
cout << endl;
cout << "x is :\t" << x << "\n" << endl;
system ("pause");
return 0;
}
(All the libraries are included because I write many problems with this same program, and I don't want to keep changing it. In a real program I know it's extra overhead, but this is only for testing.)
TIA
