include <cstdlib>
#include <iostream>
usingnamespace std;
int main(int argc, char *argv[])
{
int choice, Prounds, ap;
Prounds = 5;
ap = 1;
cout<<"This is a atbg (adventure text based game) and at each situation,\n";
cout<<"you will be presented with four choices. Type in the number of\n";
cout<<"the choice you choose.\n\n\n";
cout<<"You wake up inside of a tent. You look around,\n";
cout<<"and find a pistol with 5 shots in it, a piece of paper,\n";
cout<<"and a strange green device with a big Red button on it.\n";
cout<<"What do you do?\n\n";
cout<<"1. Look outside the tent\n";
cout<<"2. Press the big red button.\n";
cout<<"3. Study the gun.\n";
cout<<"4. Study the paper.\n";
cin>>choice;
if (choice=1)
{
cout<<"You look outside, to learn that a blizzard is\n";
cout<<"Raging and it is too blurry to make out anything.\n";
cout<<"You quickly withdraw your head.\n";
cout<<"Now what do you do?\n";
cout<<"1. Press the big red button.\n";
cout<<"2. Study the gun.\n";
cout<<"3. Study the paper.\n";
cin>>choice;
if (choice = 1)
{
cout<<"Lightning strikes the tent and you die!";
cout<<"GAME OVER...";
return 0;
}
if (choice = 2)
{
cout<<"The gun is a 9 mm gun with 5 bullets in the mag.\n";
cout<<"What do you do?\n";
cout<<"1.Go to sleep\n";
cout<<"2.Load the gun and bum rush outside.\n";
cout<<"3.Commit suicide\n";
cin>>choice;
}
if (choice = 3)
{
} }
if (choice = 2)
{
cout<<"Lighting strikes the tent and you die.\n";
cout<<"GAME OVER...";
return 0;
}
if (choice = 3)
{
cout<<"The gun is a 9 mm gun with 5 bullets in the mag.\n";
cout<<"Suddenly, the gun fires and kills you.\n";
cout<<"GAME OVER";
return 0;
}
if (choice = 4)
{
cout<<"The paper reads: You will die.\n";
cout<<"A polar bear attacks the tent and you die.\n";
cout<<"GAME OVER\n";
return 0;
}
else
{
cout<<"Game over, you neglected to follow teh rules.";
return 0;
}
return 0;
}
cin.get() will stop the screen until they hit enter.
Actually I believe it waits until the user presses the mythical "any" key.
Also you may (really you don't need to always do this, but it never hurts) want to call cin.sync() just in case one of those "any" keys are waiting in the buffer.
#include <cstdlib>
#include <iostream>
usingnamespace std;
int main(int argc, char *argv[])
{
int choice, Prounds, ap;
Prounds = 5;
ap = 1;
cout<<"This is a atbg (adventure text based game) and at each situation,\n";
cout<<"you will be presented with four choices. Type in the number of\n";
cout<<"the choice you choose.\n\n\n";
cout<<"You wake up inside of a tent. You look around,\n";
cout<<"and find a pistol with 5 shots in it, a piece of paper,\n";
cout<<"and a strange green device with a big Red button on it.\n";
cout<<"What do you do?\n\n";
cout<<"1. Look outside the tent\n";
cout<<"2. Press the big red button.\n";
cout<<"3. Study the gun.\n";
cout<<"4. Study the paper.\n";
cin>>choice;
if (choice == 1) //ALWAYS when doing IFs, and some of the loops you need to to double = :D
{
cout<<"You look outside, to learn that a blizzard is\n";
cout<<"Raging and it is too blurry to make out anything.\n";
cout<<"You quickly withdraw your head.\n";
cout<<"Now what do you do?\n";
cout<<"1. Press the big red button.\n";
cout<<"2. Study the gun.\n";
cout<<"3. Study the paper.\n";
cin>>choice;
if (choice == 1)
{
cout<<"Lightning strikes the tent and you die!\n";
cout<<"GAME OVER...";
return 0;
}
elseif (choice == 2)
{
cout<<"The gun is a 9 mm gun with 5 bullets in the mag.\n";
cout<<"What do you do?\n";
cout<<"1.Go to sleep\n";
cout<<"2.Load the gun and bum rush outside.\n";
cout<<"3.Commit suicide\n";
cin>>choice;
}
elseif (choice == 3)
{
} }
if (choice == 2)
{
cout<<"Lighting strikes the tent and you die.\n"; // You needed another \n here...
cout<<"GAME OVER...";
return 0;
}
elseif (choice == 3)
{
cout<<"The gun is a 9 mm gun with 5 bullets in the mag.\n";
cout<<"Suddenly, the gun fires and kills you.\n";
cout<<"GAME OVER";
return 0;
}
elseif (choice == 4)
{
cout<<"The paper reads: You will die.\n";
cout<<"A polar bear attacks the tent and you die.\n";
cout<<"GAME OVER\n";
return 0;
}
else
{
cout<<"Game over, you neglected to follow teh rules.";
return 0;
}
return 0;
}
Please see the thread titled "Console closing down" near the top of this forum page. It concerns your problem. It's a sticky thread because the problem appears so frequently in this forum.