I got the main code of my game working and I got my menu set up with a switch statement and I put that inside a seperate function called void Print_Menu(char X); I put the switch statement write under my menu cout display so basically if a user hit's 1 the rules display, hits 2, highest score, hits 3 goes to game. However if I hit 1 it displays the rules then goes straight to the game, how do I get it to pause until a user hit's 3?
Help with menu for simple C++ game?
The following changes achieve this:
...
cin %26gt;%26gt; X;
switch (X) {
case '1':;
cout %26lt;%26lt; "Help and Game Rules :" %26lt;%26lt; endl;
Print_Menu('x');
break;
case '2':;
cout %26lt;%26lt; " The Highest Score is : " %26lt;%26lt; endl;
Print_Menu('x');
break;
case '3':
break;
}...
Reply:if you haven't already, include %26lt;conio.h%26gt; which has the getch() function.
getch() pauses the program until a key is pressed then returns the char of that key.
Put getch() inbetween each cout and the break in the switch statement. that should work
Reply:encapsulate your code in a do while loop:
do{
your code
}
while(variable != 3)
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment