Advertisement

How do I make a simple text game exit if you run out of money?

Started by April 27, 2002 08:26 AM
3 comments, last by mx1 22 years, 7 months ago
I am trying to make a simple text game with a menu loop and the user will make money from random numbers. I want to be able to make it say, "You Lose" and then exit if the user runs out of money. I cant quite figure out how to do this, I tried an if statement like this, if(money < 1) bStillPlaying = false; And in the first of the code I made bStillPlaying = true; and it does exit if I select exit from the menu but I cant get an if statement to make the loop stop. Is there another way to do this? [edited by - mx1 on April 27, 2002 9:41:25 AM]
Here is the code.



#include <iostream>
#include <stdlib.h>
#include <ctime>
#include <cstdlib>
#include <string>
using namespace std;
void DrawMenu();
void DrawMenu()
{
cout <<"\t\t********** GAME MENU **********\n";
cout <<"\t\t 1. New Game \n";
cout <<"\t\t 2. lose some money \n";
cout <<"\t\t 3. view funds \n";
cout <<"\t\t 4. Exit \n";
}


int main()
{

int money =3;

bool bStillPlaying = true;
int choice = 0;

while(bStillPlaying)
{
DrawMenu();
cout <<"Choose from the menu:";
cin >> choice;
switch(choice)
{
case 1: cout <<"new game!\n";
break;
case 2: cout <<"lose money"< money--;
break;
case 3: cout <<"your funds\n";
cout<<"money " < break;
case 4: bStillPlaying = false;
cout <<"Game Over Already?\n";
break;
}
}
system("PAUSE");
return 0;
}



So where would I put an if statement or whatever to make the game loop end if money == 0 ?

Option 2 in the menu is just to see if it would work and make it exit.
Please help.


[edited by - mx1 on April 27, 2002 9:39:09 AM]
Advertisement
Either in the Case 2 after you substracted some money or completely after the switch statement.
...
Cool, thanks for the reply.
Your right, it works if I put it in case 2. I didn''t think about that at first and I was only using case 2 like that to see if it would work, lol.
Thanks again.=)
I have a tip for you guys:

#include <shit>.....
#define shit.....

//here:
void drawmenu();
void drawmenu()
{
bla...
}
int main()
{
shit....
}

/*you dont have to put a declarition or whatever if you put the code before main()*/

like this

#include <shit>.....
#define shit.....

//delete the "void drawmenu();":
void drawmenu()
{
bla...
}
int main()
{
shit....
}

#include

_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_
Can someone be nice and help me on my way to be the next Hideo Kojima?

This topic is closed to new replies.

Advertisement