Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.

How to Loop this program?

include <iostream>

using namespace std;

void playgame()

{

cout << "Play game called";

}

void loadgame()

{

cout << "Load game called";

}

void playmultiplayer()

{

cout << "Play multiplayer game called";

}

int main()

{

int input;

cout<<"1. Play game\n";

cout<<"2. Load game\n";

cout<<"3. Play multiplayer\n";

cout<<"4. Exit\n";

cout<<"Selection: ";

cin>> input;

switch ( input ) {

case 1: // Note the colon, not a semicolon

playgame();

break;

case 2: // Note the colon, not a semicolon

loadgame();

break;

case 3: // Note the colon, not a semicolon

playmultiplayer();

break;

case 4: // Note the colon, not a semicolon

cout<<"Thank you for playing!\n";

break;

default: // Note the colon, not a semicolon

cout<<"Error, bad input, quitting\n";

break;

}

cin.get();

}

/// I want it to say "Incorrect selection, Enter a valid selection" till i enter 1,2,3 or 4 ?

/// How to do this ?

1 Answer

Relevance
  • 8 years ago
    Favorite Answer

    Use a while loop that keeps asking the user for another input until a valid input is given.

Still have questions? Get your answers by asking now.