Tuesday, July 28, 2009

How do you get the following computer programming code to work on microsoft visual c++ express edition?

#include %26lt;iostream%26gt;


#include %26lt;math.h%26gt;


using namespace std;


int main(){


for(int i=1; i%26lt;=64; i++){


cout%26lt;%26lt;"cell number "%26lt;%26lt;i%26lt;%26lt;" = "%26lt;%26lt;pow(2,i)%26lt;%26lt;endl;


}


return 0;


}








*the code works on my school computers, but not on microsoft visual c++ express edition. can anyone please tell me how to get it to work on microsoft visual c++ express edition step-by-step?

How do you get the following computer programming code to work on microsoft visual c++ express edition?
C++ requires all types to be correct and the errors that show say that the pow(a,b) is incorrect.


You need to make and the constant 2 into 2.0 or cast it as double


That should take care of the mismatching type problems
Reply:you need to cast your constant 2 into either a float or a double before passing it to pow().





The problem is that the first argument should be either a float or a double, and you give it an int. The compiler need to convert it, but can't know for sure which one you want.





So go for one of those


1) pow((float)2, i) %26lt;%26lt; endl;


2) float two = 2.0f; pow(two, i);


3) pow(2.0f, i);


4) pow(2.0, i);
Reply:I can't see any errors in the code... what error is the compiler throwing at you? You're probably missing a library or something. More details please! (The most useful detail would be what error the compiler is giving you - compiler error messages are there to help, not just to fill up space!).


No comments:

Post a Comment