   if problems
  i have nearly finished a game but i have a sentence telling the user to enter attack or potion.and underneath it says:cin >> choice;if ( choice = attack )The compiler wont accept if ( choice = attack )why not and how do i fix this?????   
  What does the compiler do? What is choice and what is attack? You are aware that you are trying to assign choice to attack and check choice's new value, right? If you want to compare them you should use ==, not =. Also if you intend to check if the user entered attack, you should make it a string, like this "attack".   ;  this is my code.when i run it my program has no writing.whats wrong with it?#include <iostream>#include <ctime>#include <string>#include <stdio.h>using namespace std;int main(void){int health, opHealth, potion, opPotion, attack, opAttack;string choice;potion = 1;opPotion = 1;health = 30;    opHealth = 30;bool death = false, opDeath = false;while (true);{srand(time(NULL));cout << "Type attack to fight or potion to heal: " << endl;cin >> choice;if ( choice == "attack" ){attack = (rand() % 7) + 1;cout << "You have done " << attack << "damage." << endl;cout << "Your opponent now has " << opHealth - attack << "health left." << endl;}else{    (potion - 1);cout << "You now have " << health + 10 << "health." << endl;}   cout << "It's now the opponents turn." << endl;opAttack = (rand() % 7) + 1;cout << "The opponent has done " << opAttack << "damage." << endl;cout << "You have " << health - opAttack << "health." << endl;if (health == 0){    (death == true);cout << "You have lost. GAMEOVER." << endl;}else{(opDeath == true);cout << "You have won..... WELL DONE!!!!" << endl;}    }return 0;};  I think this is what you were looking for:#include <iostream>#include <ctime>#include <string>#include <stdio.h>using namespace std;int main(){int health, opHealth, potion, opPotion, attack, opAttack;string choice;potion = 1;opPotion = 1;health = 30;opHealth = 30;bool death = false, opDeath = false;srand(time(NULL));while ((death==false) && (opDeath == false)){cout << "Type attack to fight or potion to heal: " << endl;cin >> choice;    if ( choice == "attack" )    {    attack = (rand() % 7) + 1;    cout << "You have done " << attack << "damage." << endl;    cout << "Your opponent now has " << opHealth - attack << "health left." << endl;    opHealth=opHealth-attack;    }    else    {    potion--;    cout << "You now have " << health + 10 << "health." << endl;    health=health+10;    }    cout << "It's now the opponents turn." << endl;opAttack = (rand() % 7) + 1;cout << "The opponent has done " << opAttack << "damage." << endl;cout << "You have " << health - opAttack << "health." << endl;health=health-opAttack;if (health <= 0){death = true;cout << "You have lost. GAMEOVER." << endl;}if (opHealth <=0){opDeath = true;cout << "You have won..... WELL DONE!!!!" << endl;}}system("pause");return 0;}please don't just copy-paste it.a few remarks:your loop : while(true) is an infinate loop since true is always true. you need to check if death is true or false.using "cout<<health-1" doesn't actually change the value of health it just shows on the screen how much health-1 is.Go through my and your code and compare them. And feel free to ask any questions :);Quote:Original post by CTarWhat does the compiler do? What is choice and what is attack? You are aware that you are trying to assign choice to attack and check choice's new value, right? If you want to compare them you should use ==, not =. Also if you intend to check if the user entered attack, you should make it a string, like this "attack".What he said. More specifically, we still don't know:- What does the compiler do? Which errors do you get?- What do you expect choice and attack to be? (I see attack is declared as an int, but in the above code you compare choice to "attack", that is, the string literal instead of the int variabl. Which do you actually *intend* to do? What is the player supposed to type in choice?;  The fact that you just ge a black screen is because of this:while(true);with the semicolon after it, this while loop only has effect on the first statement which is, well, nothing. this would be the same aswhile(true){//do nothing}take a look at the two ways of making a while loop:while (death == false)onestatement;anotherstatement;here only onestatement will be repeated.and while(death ==false){onestatement;anotherstatement;andanotherone;}here all three statements will be repeated.   ;  I tried changing it and it worked!!!thx.   