### Game Over when life is less than or equal to zero?

I have this code. Can someone help me print ("Game over") to the program when the health of the log/rock goes less than or equal to zero? Thanks.

 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314`` `````` #include #include #include #include #include using namespace std; class character{ public: void name(string Name= "Adriel") { cout << "Name: " << Name << endl; } void hp (int IHP=50) { cout << "HP: " << IHP << endl; } void mp (int IMP=50) { cout << "MP: " << IMP << endl; } int inflictdamage(int RHealth,string type,string Weapons[5], int damage[5] ) { int CHealth=((RHealth-damage[0]) || (RHealth-damage[1]) || (RHealth-damage[2]) || (RHealth-damage[3]) || (RHealth- damage[4])); cout << "\nWhat do you want to do first?" << endl; cout << Weapons[0] << " : 25\n" << Weapons [1] << " : 20\n" << Weapons[2] << " : 15\n"<< Weapons[3] << ": 10\n" << Weapons [4] << " : 5\n" << endl; cin >>type; START: if (type==Weapons[0]) { RHealth=RHealth-damage[0]; cout << "Strength of Rock: " << RHealth << endl; cout << "\nWhat do you want to do next?" << endl; cout << Weapons[0] << " : 25\n" << Weapons [1] << " : 20\n" << Weapons[2] << " : 15\n"<< Weapons[3] << ": 10\n" << Weapons [4] << " : 5\n" << endl; cin >>type; } else if (type==Weapons[1]) { RHealth=RHealth-damage[1]; cout << "Strength of Rock: " << RHealth << endl; cout << "\nWhat do you want to do next?" << endl; cout << Weapons[0] << " : 25\n" << Weapons [1] << " : 20\n" << Weapons[2] << " : 15\n"<< Weapons[3] << ": 10\n" << Weapons [4] << " : 5\n" << endl; cin >>type; } else if (type==Weapons[2]) { RHealth=RHealth-damage[2]; cout << "Strength of Rock: " << RHealth << endl; cout << "\nWhat do you want to do next?" << endl; cout << Weapons[0] << " : 25\n" << Weapons [1] << " : 20\n" << Weapons[2] << " : 15\n"<< Weapons[3] << ": 10\n" << Weapons [4] << " : 5\n" << endl; cin >>type; } else if (type==Weapons[3]) { RHealth=RHealth-damage[3]; cout << "Strength of Rock: " << RHealth << endl; cout << "\nWhat do you want to do next?" << endl; cout << Weapons[0] << " : 25\n" << Weapons [1] << " : 20\n" << Weapons[2] << " : 15\n"<< Weapons[3] << ": 10\n" << Weapons [4] << " : 5\n" << endl; cin >>type; } else if (type==Weapons[4]) { RHealth=RHealth-damage[4]; cout << "Strength of Rock: " << RHealth << endl; cout << "\nWhat do you want to do next?" << endl; cout << Weapons[0] << " : 25\n" << Weapons [1] << " : 20\n" << Weapons[2] << " : 15\n"<< Weapons[3] << ": 10\n" << Weapons [4] << " : 5\n" << endl; cin >>type; } goto START; } }; class obstacle{ public: void rock(string Name= "Rock", int Strength= 50) { cout << "\nName: " << Name << endl; cout << "Strength: "<< Strength << endl; } void log(string Name= "Log", int Strength= 40) { cout << "\nName: " << Name << endl; cout << "Strength: "<< Strength << endl; } }; int SecondInflictDamage(int LHealth,string type,string Weapons[5], int damage[5] ) { SECOND: cout << "\nWhat do you want to do first?" << endl; cout << Weapons[0] << " : 25\n" << Weapons [1] << " : 20\n" << Weapons[2] << " : 15\n"<< Weapons[3] << ": 10\n" << Weapons [4] << " : 5\n" << endl; cin >>type; FINISH: if (type==Weapons[0]) { LHealth=LHealth-damage[0]; cout << "Strength of Log: " << LHealth << endl; cout << "\nWhat do you want to do next?" << endl; cout << Weapons[0] << " : 25\n" << Weapons [1] << " : 20\n" << Weapons[2] << " : 15\n"<< Weapons[3] << ": 10\n" << Weapons [4] << " : 5\n" << endl; cin >>type; } else if (type==Weapons[1]) { LHealth=LHealth-damage[1]; cout << "Strength of Log: " << LHealth << endl; cout << "\nWhat do you want to do next?" << endl; cout << Weapons[0] << " : 25\n" << Weapons [1] << " : 20\n" << Weapons[2] << " : 15\n"<< Weapons[3] << ": 10\n" << Weapons [4] << " : 5\n" << endl; cin >>type; } else if (type==Weapons[2]) { LHealth=LHealth-damage[2]; cout << "Strength of Log: " << LHealth << endl; cout << "\nWhat do you want to do next?" << endl; cout << Weapons[0] << " : 25\n" << Weapons [1] << " : 20\n" << Weapons[2] << " : 15\n"<< Weapons[3] << ": 10\n" << Weapons [4] << " : 5\n" << endl; cin >>type; } else if (type==Weapons[3]) { LHealth=LHealth-damage[3]; cout << "Strength of Log: " << LHealth << endl; cout << "\nWhat do you want to do next?" << endl; cout << Weapons[0] << " : 25\n" << Weapons [1] << " : 20\n" << Weapons[2] << " : 15\n"<< Weapons[3] << ": 10\n" << Weapons [4] << " : 5\n" << endl; cin >>type; } else if (type==Weapons[4]) { LHealth=LHealth-damage[4]; cout << "Strength of Log: " << LHealth << endl; cout << "\nWhat do you want to do next?" << endl; cout << Weapons[0] << " : 25\n" << Weapons [1] << " : 20\n" << Weapons[2] << " : 15\n"<< Weapons[3] << ": 10\n" << Weapons [4] << " : 5\n" << endl; cin >>type; } else { cout << "Invalid. Try again." << endl; goto SECOND; } goto FINISH; } int inflictdamage(int RHealth,string type,string Weapons[5], int damage[5] ) { FIRST: cout << "\nWhat do you want to do first?" << endl; cout << Weapons[0] << " : 25\n" << Weapons [1] << " : 20\n" << Weapons[2] << " : 15\n"<< Weapons[3] << ": 10\n" << Weapons [4] << " : 5\n" << endl; cin >>type; START: if (type==Weapons[0]) { RHealth=RHealth-damage[0]; cout << "Strength of Rock: " << RHealth << endl; cout << "\nWhat do you want to do next?" << endl; cout << Weapons[0] << " : 25\n" << Weapons [1] << " : 20\n" << Weapons[2] << " : 15\n"<< Weapons[3] << ": 10\n" << Weapons [4] << " : 5\n" << endl; cin >>type; } else if (type==Weapons[1]) { RHealth=RHealth-damage[1]; cout << "Strength of Rock: " << RHealth << endl; cout << "\nWhat do you want to do next?" << endl; cout << Weapons[0] << " : 25\n" << Weapons [1] << " : 20\n" << Weapons[2] << " : 15\n"<< Weapons[3] << ": 10\n" << Weapons [4] << " : 5\n" << endl; cin >>type; } else if (type==Weapons[2]) { RHealth=RHealth-damage[2]; cout << "Strength of Rock: " << RHealth << endl; cout << "\nWhat do you want to do next?" << endl; cout << Weapons[0] << " : 25\n" << Weapons [1] << " : 20\n" << Weapons[2] << " : 15\n"<< Weapons[3] << ": 10\n" << Weapons [4] << " : 5\n" << endl; cin >>type; } else if (type==Weapons[3]) { RHealth=RHealth-damage[3]; cout << "Strength of Rock: " << RHealth << endl; cout << "\nWhat do you want to do next?" << endl; cout << Weapons[0] << " : 25\n" << Weapons [1] << " : 20\n" << Weapons[2] << " : 15\n"<< Weapons[3] << ": 10\n" << Weapons [4] << " : 5\n" << endl; cin >>type; } else if (type==Weapons[4]) { RHealth=RHealth-damage[4]; cout << "Strength of Rock: " << RHealth << endl; cout << "\nWhat do you want to do next?" << endl; cout << Weapons[0] << " : 25\n" << Weapons [1] << " : 20\n" << Weapons[2] << " : 15\n"<< Weapons[3] << ": 10\n" << Weapons [4] << " : 5\n" << endl; cin >>type; } else { cout << "Invalid. Try again. " << endl; goto FIRST; } goto START; } void main () { string Weapons[5] = {"Sword", "Spear", "Arrow", "Dagger" , "Knife"}; int damage[5]={25, 20, 15, 10, 5}; int CHealth; int RHealth=50; int LHealth=40; int number; string type; character first; first.name(); character second; second.hp(); character third; third.mp(); obstacle fourth; fourth.rock(); obstacle fifth; fifth.log(); TRY: cout << "\nWhat will you strike first? ROCK or LOG: "; cin >> type; if (type=="ROCK") { cout<< inflictdamage(RHealth, type,Weapons, damage); } else if (type=="LOG") { cout << SecondInflictDamage(LHealth,type,Weapons, damage ); } else { cout << "Invalid. Try again.\n" << endl; goto TRY; } getch(); }``````
Sorry, I can't understand your code. Any notes?
In every if statement put another if statement like this:
 ``12345678910111213141516171819`` ``````if (type==Weapons[0]) { RHealth=RHealth-damage[0]; if (RHealth==0 || RHealth<0) // The || means OR, RHealth<0 if RHealth is smaller than 0 { cout << "Strength of Rock: " << RHealth << endl; cout<<"Sorry, you died"< return 0; //Closes the program else { cout << "Strength of Rock: " << RHealth << endl; cout << "\nWhat do you want to do next?" << endl; cout << Weapons[0] << " : 25\n" << Weapons [1] << " : 20\n" << Weapons[2] << " : 15\n"<< Weapons[3] << ": 10\n" << Weapons [4] << " : 5\n" << endl; cin >>type; } }``````

If you don't know what is Sleep() go here;http://www.dreamincode.net/forums/topic/16391-sleep-command-in-c/
Hope that helps you.
I am looking forward seeing your final code.
Also amchinese is right, can you please write some notes? It was a bit difficult for me to understand it, i am not a compiler you see!
Last edited on
Topic archived. No new replies allowed.