pow function issues, need help.

May 28, 2012 at 10:53pm
I'm just beginning c++ and i need some help with this code. I'm trying to figure out why my command prompt gives my the answer 8 when i run and build this code. I thought the 'pow' function would take the 5 and raise it to the 8th power which would be 390,625.. so why is my code not working? thanks



#include <iostream>
#include <cmath>
using namespace std;


int main(){

double pow;

pow = (5.0, 8.0);

cout << pow << endl;

return 0;
}


May 28, 2012 at 10:56pm
check the following

http://www.cplusplus.com/reference/clibrary/cmath/pow/

I think pow will return a float
May 28, 2012 at 11:06pm
i tried this, it still got me the same answer so im still doing something completely wrong here

#include <iostream>
#include <cmath>
using namespace std;


int main(){

float pow;

pow = (5.0, 8.0);

cout << pow << endl;

return 0;
}
May 29, 2012 at 12:51am
???? That's sooo NOT a function call. That's merely operator comma.

1
2
3
4
//First:  Don't use the function's name to declare a variable.  Don't use pow.
double powResult;  //Better.

powResult = pow(5.0, 8.0);
May 29, 2012 at 1:59am
Thanks man, yeah im really new to this but that makes sense :)
Topic archived. No new replies allowed.