Friday, July 31, 2009

Can someone who knows C++ help me?

I can't get my code to run. Could someone look at it and tell me whats wrong.





//


// Program: Sum of Squares


// Written by: E.A.


// Date: Jan 13, 2008


//


#include %26lt;iostream%26gt;


#include %26lt;cmath%26gt;





using namespace std;





int main()


{


int m, n, Side_one, Side_two, Hypotenuse; //variables used in program





//input data


//calculate side one





cout %26lt;%26lt; "Enter m:\n ";


cout %26lt;%26lt; "Side one: " %26lt;%26lt; pow(float (m),2) - pow(float (n) ,20);


cin %26gt;%26gt; Side_one;





//calculate side two


cout %26lt;%26lt; "Enter n:\n ";


cin %26gt;%26gt; "Side_two: " %26lt;%26lt; 2*m*n;


cin %26gt;%26gt; Side_two;


cout %26lt;%26lt; "\n\n";





//calculate hypotenuse


cout %26lt;%26lt; "Hypotenuse: " %26lt;%26lt; sqrt(pow(float (Side_one), 2)+pow(float (Side_two),2));


cin %26gt;%26gt; Hypotenuse;


cout %26lt;%26lt; "n\n";





return (0);


}


//


//End of main


//

Can someone who knows C++ help me?
Your problem is in line 24, where you have the following statement...





cin %26gt;%26gt; "Side_two: " %26lt;%26lt; 2*m*n;





The cin statement can't take a value into a string "Side_two:". Make the cin statement point to a variable and all will be fine.
Reply:The person above is correct. I'm rusty on C++ but there is something wrong having a %26lt;%26lt; symbol in the cin statement:





cin %26gt;%26gt; "Side_two: " %26lt;%26lt; 2*m*n;





There should be a cout when using %26lt;%26lt;.


No comments:

Post a Comment