Thursday, July 30, 2009

C++ problem?

we want day health to change when we attack





plz help





#include %26lt;cstdlib%26gt;


#include %26lt;iostream%26gt;





using namespace std;





int main(void)


{


int dayhealth = 100;


int plhealth = 50;


string name;


char answer;


int attack = 10;





cout %26lt;%26lt;"gahhh?" %26lt;%26lt; endl;


cin %26gt;%26gt; name;





cout %26lt;%26lt; name %26lt;%26lt; endl;





cout%26lt;%26lt; "player" %26lt;%26lt; plhealth %26lt;%26lt; "\n\nday" %26lt;%26lt; dayhealth %26lt;%26lt; endl;





cout%26lt;%26lt; "atk?" %26lt;%26lt; endl;


cin%26gt;%26gt; answer;





if (answer = 'yes')


{


cout %26lt;%26lt; "gahhh" %26lt;%26lt; dayhealth - attack %26lt;%26lt; endl;





cout %26lt;%26lt; dayhealth %26lt;%26lt; endl;


}








system("PAUSE");


return EXIT_SUCCESS;


}

C++ problem?
You are never taking anything away from dayhealth. The statement dayhealth-attack does the subtraction for the print statement but it does not assign it back to day health. If you want to assign it back you should use -= instead of just minus.





Also the comparison of answer == 'yes' is still not correct because answer is a single character and can only be compared to a single character =='y'
Reply:hmmm.. what's the problem?


if the problem is that nothing happens when you execute this code. It must be the if statement.


"if(answer='yes')" should be "if(answer=='yes')"





^^,

marguerite

No comments:

Post a Comment