-
int main()
ok, this is just a portion of my actual program, I am having trouble down near the bottom, if you have any suggestions please feel free, I am always open to suggestions.
cout << "press 1 to enter or 2 not to enter"<<endl<<endl<<endl;
cin >> x;
if (x==1)
{
cout << "Would you like a bed for the night or tend to the bar?"<<endl
<< "press 1 for a room or 3 to tend to the bar."<<endl<<endl;
cin >> x;
if (x==1)
int main(1);
{
cout << "very well sir, your baggage will be taken to your room and your horses will be"<<endl
<<"put in the stall around the corner. Dinner is at 7:00pm sharp, dont be late."<<endl
<<"Thank you sir and enjoy your stay at the Green Dragon Inn...press 1 if you "<<endl
<<"would like to go to your room or 4 if you would like to attend the game room."
<<endl<<endl;
cin >> x;
if (x==1)
{ cout << "Right sir, your room is down that hall there and to the left, first door"<<endl
<< "on the right marked 09. Enjoy your rest sir, if you need anything dont be afraid"
<< "to come out and ask one of our boys for help."<<endl<<endl;
return 0;
}
if (x==4)
cout << "Welcome to the game room sir, I am Master Meriadoc. I will be your host"<<endl
<< "for tonight. Ok, to get things started press 1 if you would like to play the "<<endl
<< "game or press 5 if you would like to leave."<<endl<<endl;
cin >> x;
if (x==5)
{
*"this is where I want to loop it back to where it says int main(1), any suggestions?"
}
{
-
I can think of three ways that this could be attempted.
First, and most likely, use a loop; probalby with a flag, depending on what comes later. For example how does player cancel the game? Does player need to go back to the top or can he decide he doesn't want to play any of the games and can they go to the room directly, without going to back to the top?
An alternative, would be to try the keyword continue.
Last, and definitely last, the goto() command could be considered, but ONLY as a last resort.
-
Try something like this for your prompts, and put the entire thing in a do while loop or forever loop with a break statement to exit if you want it to cycle through more than once.
#include <iostream.h>
int main()
{
int number;
cout << "enter 1 blah enter 2 blah ";
cin >> number;
switch(number)
{
case 1: cout << "stuff for option one";
break;
case 2: cout << "stuff for option two";
break;
default: cout << "That wasn't a valid option.";
break;
}
return 0;
}