# Thread: pow() doesnt return a double?

1. ## pow() doesnt return a double?

Code:
```#include <iostream.h>
#include <stdlib.h>
#include <math.h>

int main()
{

double result, x = 3.0, y = 2.0;
result = pow(x, y);

cout << result << endl;

system("PAUSE");
return 0;
}```

The above gives me a result of 9 instead of 9.0
as the book here says.

Same thing w/ abs() or fabs() or floor() etc. The arguments are doubles but the value returned are integers.

I did something wrong or do I need to use the "cout.setf....cout.precision" thingy, but this book doesnt say anything abt it.

Thanx.

2. ## Re: pow() doesnt return a double?

Originally posted by FloatingPoint
The above gives me a result of 9 instead of 9.0
as the book here says.
the computer will truncate any extra zeroes... set precision to 1 if you want them to show up... it truncates them at a sig digit because you don't want 9.00000000000000 to show up...

3. Code:
```#include <iostream.h>
#include <iomanip.h>
#include <math.h>
int main()
{
double result, x=3.0,y=2.0;
result = pow(x,y);
cout.setf(ios::fixed);
cout.precision(5);
cout<<result<<endl;
return 0;
}```
Try this...

-LC

4. Or rather this:
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
int main()
{
double result, x=3.0,y=2.0;
result = pow(x,y);
cout.setf(ios::fixed);
cout.precision(5);
cout<<result<<endl;
return 0;
}

5. Thanx all.

I tried

double result = 9.0;
cout << result << endl;

and it gave me a 9.

Is this is how it's supposed to be? I mean the only way is to use that "cout.setf.....precision" block?

Thanx.

6. ## Re: Re: pow() doesnt return a double?

Originally posted by major_small
the computer will truncate any extra zeroes... set precision to 1 if you want them to show up... it truncates them at a sig digit because you don't want 9.00000000000000 to show up...
Yea, I guess so.

Thanx again.

7. Corned Bee;

Yours flashes off the screen too fast. How do I put a "press any key to continue" there?

#include <stdlib.h> or <stdlib> doesnt seem to work.

Thanx.

8. Would be <cstdlib>, but...

a) When launching from within VC++ it gets stopped anyway.
b) The usual console app is launched from the command line where you have a console window that stays.

9. Included that and I'm using Dev C++ 4 but it doesnt stay.

10. Of course it doesn't. No header file makes the app stay by itself.