I recently start to learn some C++ by watching some tutorials on YouTube, I learnt the random number generator and "coocked up" a game with it, I need help with the else part from the while loo[ it seems to just use the else loop while the aspirine int reaches 0 also some improvements and tips for my code are welcome :)
#include <iostream>
#include <cstdlib>
#include <ctime>
usingnamespace std;
int aspirine = 3;
int main()
{
int humans, zombies, enter, aux, max;
cout<<""<<endl;
cout<<" HUMANS VS ZOMBIES"<<endl<<endl<<endl<<endl;
cout<<"PRESS ENTER TO BEGIN"<<endl;
cin.get();
cout<<""<<endl;
cout<<""<<endl;
cout<<"INPUT THE AMOUNT OF ENEMIES"<<endl;
cin>>zombies;
cout<<"You hear a lot of noise outside and you are going to check out what's happening"<<endl<<endl;
cin.get();
cin.get();
cout<<"All of a sudden you get attacked by "<<zombies<<" zombies."<<endl;
cin.get();
cout<<"You get scared and run back inside your home and take your gun"<<endl;
cin.get();
cout<<"After you catch your breath you go outside with the gun and try to take them out to defend your home and kids"<<endl;
cin.get();
cout<<"There is a 10% chance to miss and not kill the zombie"<<endl;
cin.get();
cout<<"Press enter to fire your gun"<<endl;
cin.get();
srand(time(0));
aux = rand()%100+1;
int chance=10;
while (zombies != 0 && chance <= 100 && aspirine !=0){
if (aux<chance)
{
cout<<"You missed and the zombie bit you, good thing you had an Aspirine to stop the infection"<<endl;
aspirine = aspirine-1;
cout<<"You only have "<<aspirine<<" Aspirine left."<<endl;
}
else
{
zombies = zombies - 1;
cout<<"You killed the zombie, only "<<zombies<<" left."<<endl;
cout<<"You became tired after killing this zombie so your chance of missing increased by 5%"<<endl;
cin.get();
chance = chance+5;
}
}
return 0;
}
It has nothing to do with your while statement, it's only inside the while loop.
I think if you insert this code you'll be able to figure out what you need.
1 2 3
while (zombies != 0 && chance <= 100 && aspirine !=0){
cout << "A= " << aux << " C = " << chance << endl;
if (aux<chance)
Just thinking here: aux is a randomly generated number, so what are the chances that aux would be less than chances the first few times through the while loop?