Skip to content

Instantly share code, notes, and snippets.

Created October 26, 2013 02:06
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save anonymous/7164487 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
int GetUserChoice()
{
int choice;
cout << "Please select one of the following options:" << endl;
cout << "1. Rock" << endl;
cout << "2. Paper." << endl;
cout << "3. Scissors" << endl;
cout << " or " << endl;
cout << "4. Quit " << endl;
cout << "Your choice is: ";
cin >> choice;
cout << endl;
if ( choice == 1 )
{
cout << "You chose rock." << endl;
}
else if ( choice == 2 )
{
cout << "You chose paper." << endl;
}
else if ( choice == 3 )
{
cout << "You chose scissors." << endl;
}
else if ( choice == 4 )
{
cout << "You quit. Thank you for using the program." << endl;
}
else if ( choice > 4 || choice < 1 )
{
cout << "Please enter a valid choice\n" << endl;
}
return choice;
}
int main()
{
PrintNameHeader();
int choice = 1;
do
{
int choice = GetUserChoice();
}while ( choice != 4);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment