こんにちは、私は現在、switch ステートメントをメニューの先頭に戻すのに苦労しています。代わりに、ユーザーが正しい選択を選択しない限り、私が望んでいない別のメイン機能に進みます。
とにかく私が持っているコードは次のとおりです。
int main()
{
int choice;
bool menu = true;
cout <<"Please select one of the following options: \n";
cout << "1: Play\n"
"2: Help\n"
"3: Config\n"
"4: Quit\n";
cout << "Enter your selection (1, 2,3 or 4): ";
cin >> choice;
//*****************************************************************************
// Switch menu to display the menu.
//*****************************************************************************
if(menu)
{
switch (choice)
{
case 1:
cout << "You have chosen play";
break;
case 2:
cout << "You have chosen help\n";
cout << "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 << "You have chosen config";
break;
case 4:
cout << "You have chosen Quit, Goodbye.";
break;
default:
cout<< "Your selection must be between 1 and 4!\n";
}
}
getchar();
getchar();
cout << "You missed " << playGame("programming");
cout << " times to guess the word programming." << endl;
}