This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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