Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do I get a switch statement to loop back into a menu
    primarykey
    data
    text
    <p>Hey everyone I'm currently having some trouble in making the switch statement coming back out around to the start of the menu. Instead it proceeds into another main function that I don't want it to unless the user chooses the right selection. </p> <p>here's the code I have anyway:</p> <pre><code>int main() { int choice; bool menu = true; cout &lt;&lt;"Please select one of the following options: \n"; cout &lt;&lt; "1: Play\n" "2: Help\n" "3: Config\n" "4: Quit\n"; cout &lt;&lt; "Enter your selection (1, 2,3 or 4): "; cin &gt;&gt; choice; //***************************************************************************** // Switch menu to display the menu. //***************************************************************************** if(menu) { switch (choice) { case 1: cout &lt;&lt; "You have chosen play"; break; case 2: cout &lt;&lt; "You have chosen help\n"; cout &lt;&lt; "Here is a description of the game Hangman and how it is played:\nThe word to guess is represented by a row of dashes, giving the number of letters, numbers and category. If the guessing player suggests a letter or number which occurs in the word, the other player writes it in all its correct positions"; break; case 3: cout &lt;&lt; "You have chosen config"; break; case 4: cout &lt;&lt; "You have chosen Quit, Goodbye."; break; default: cout&lt;&lt; "Your selection must be between 1 and 4!\n"; } } getchar(); getchar(); cout &lt;&lt; "You missed " &lt;&lt; playGame("programming"); cout &lt;&lt; " times to guess the word programming." &lt;&lt; endl; </code></pre> <p>}</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload