Trying to get a variable to randomly add or subtract from it

Hey guys im currently working on a simple programming game here are the parameters:

Rules Mel Gibson has a randon number of bullets when the game starts. Use a while loop to control the loop of firing. Three things can happen when he fires a bullet the BadGuy can
1.die the badGuys are decreased by 1 and Mel Gibson adds a life.
2. Missed the bad guys are increased by 1
3. Injured the bad guys are decreses by .5 and Mel Gibson loses a life.

The game ends when Mel runs out of bullets, his lives are -1 or bad guys are 0.
Be sure to output messages to your fans to tell them what is happening.
The winner is MelGibson if Mel has >0 lives and bad guys are 0.
After all of this works.
Hint: start the game over at least 3 times. (For Loop)

I know how the for loops and while and do while work what i am stuck on is getting the # of Bullets and live and bad guys to randomly add or subtract.

The bullets should continually decrease which i assume to be bullets-- my problem is getting lives and bad guys to increase or decrease accordingly i'll provide my code which is not even close to complete.



#include<iostream>
#include<ctime>
#include<cstdlib>
using namespace std;
int main()
{
double lives = 5, badGuys = 5, bullets;

unsigned seed = time(0);
srand(seed);

bullets = 1 + rand()% 20;





cout << "Welcome to the Lethal weapon game with....\n"
<< "You guessed it!! MelGibson OMG!!!\n\n";
cout << "The object of the game is to have a positive number of lives\n"
<< "With the number of bad guys at 0\n";
cout << "Mel Gibson will start the game with 5 lives.\n";
cout << "The game will start with 5 bad guys.\n\n";
cout << "The rules are simple :\n"
<< "Rule #1 If the Bad guy dies total bad guys is decreased by 1 and you gain a life.\n"
<< "Rule #2 If you miss the bad guys increase by 1\n"
<< "Rule #3 The bad guys are injured the bad guys are decresed by .5 and Mel Gibson loses a life.\n\n\n\n";
system("pause")
cout << "The game has begun goodluck!!\n\n\n";
cout << "This time you are starting off with " << bullets << " bullets\n";
do
{


for(bullets; bullets--)
{
if(lives == -1)
{
cout << "Mel Gibson has died.\n";
}
if(badGuys == 0 & lives >= 0)
{
cout << "The bad guys are all dead.\n";
cout << "You win!!!!!\n":

}
if(bullets == 0)
{
cout << "You are out of bullets.\n";
cout << "Game over :-(\n";

}
}


i apologize if this is not legible my first time posting on this website
Last edited on
Topic archived. No new replies allowed.