-
im stuck, cant fix..HELP
I have written a small game program text program using
if and else commands.
when i compiled it i got this message:
" C++ forbids comparison between pointer and integer"
below is the error line of my code:
if (attack =="y") {
its really got me as the rest of my program is fine.
does anyone know what the error means??
-
"y" is a string literal and considered a pointer for purposes of the comparison in that bit of code. You can't test for equality in the manner you are trying to do it. If you are testing C-style strings (characters array) you need to use the strcmp function. If you are using C++ string containers then you can do it as you have it. If you are just testing for a single character, you can do this:
Code:
char attack;
...
if( attack == 'y' )
Make sure your attack variable is an appropriate type to be comparing in the test.
-
thanks hk_,mp!! it works great!! one more question, when the player takes the hit, is there any way of displaying it on the screen, here is my example:
int PlayerH = 10; // declare varible
// you get hit so
PlayerH=PlayerH-5;
how do i display on the screen that there is only 5 helf points left??
any help would be greatly appriciated
-
cout<<"You have "<<PlayerH<<" points left.";