This code is meant to do a combat simulation for an RPG but the while loop does not end. Please can somebody tell me where Iv'e gone wrong.
#include <iostream>
using namespace std;
int combatVictory = 0;
int combatDeath = 0;
int error = 0;
void Combat(int HeroHP,int MonsterHP,int HeroAttk,int MonsterAttk,int healthPotCount, int attkPotCount, int *combatDeath, int *combatVictory, int *error);
int main()
{
int HeroHP = 1;
int MonsterHP = 150;
int HeroAttk = 15;
int MonsterAttk = 18;
int healthPotCount = 2;
int attkPotCount = 3;
return 0;
}
void Combat(int HeroHP,int MonsterHP,int HeroAttk,int MonsterAttk,int healthPotCount, int attkPotCount, int *combatDeath, int *combatVictory, int *error){
while(HeroHP>=0||MonsterHP>=0){
int combatChoice=0;
int MonsterCombatAttk=MonsterAttk;
int HeroCombatAttk=HeroAttk;
cout<<"What do you wish to do?\n"<<"1: Attack Monster\n"<<"2: Drink health potion\n"<<"3: Drink potion of Attack\n";
cin >> combatChoice;
switch(combatChoice){
case 1:
MonsterHP= MonsterHP - HeroCombatAttk;
cout << "You dealt "<<HeroCombatAttk<<" damage to the creature.\n";
cout << "The beasts health now is "<<MonsterHP<<".\n";
break;
case 2:
HeroHP = HeroHP + 10;
cout << "You have restored your Health slightly\n";
break;
case 3:
HeroCombatAttk = HeroCombatAttk + 5;
cout << "The potion has strengthened your muscles.\n";
break;
default:
cout << "You stumble in your tracks.\n";
}
switch(combatChoice){
case 1:
cout<<"The beast stumbles but still strikes.\n";
MonsterCombatAttk = MonsterCombatAttk - (HeroAttk/2);
break;
case 2:
cout<<"The beast attacks.\n";
MonsterCombatAttk = MonsterAttk;
break;
case 3:
cout<<"The beast attacks.\n";
MonsterCombatAttk = MonsterAttk;
break;
default:
cout<<"The beast takes full advantage of your mistake.\n";
MonsterCombatAttk = MonsterAttk + (HeroAttk/2);
}
HeroHP= HeroHP - MonsterCombatAttk;
}
if(HeroHP<=0){
cout<<"Your brave journey has come to it's end.\n";
cout<<"You never found out about the glory of Heroism.\n";
cout<<"Now the tale ends.\n";
Yes, that while loop said:
while Hero is alive OR while Monster is alive
As long as either one is alive, the loop keeps running. With &&, you get this:
while Hero is alive AND while Monster is alive
This way, the loop only runs until one or the other dies.