Hello! I was finishing up an assignment for my computer science class but I've run into a small problem. Everything in my program works as it should, but when the results are displayed, they are shown as ints. I was wondering if there was a way to display a string instead of a number. For example:
"1" would display as "Rock"
"2" would display as "Paper"
"3" would display as "Scissors"
"4" would display as "Lizard"
"5" would display as "Spock"
Here is my function:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
int displayChoice (int computer, int user, int result)
{
if (result == 0)
{
cout << "DRAW\n" << "Your Choice: " << user << "\nComputer's Choice: " << computer << endl;
}
if (result == 1)
{
cout << "YOU WIN!\n" << "Your Choice: " << user << "\nComputer's Choice: " << computer << endl;
}
if (result == 2)
{
cout << "COMPUTER WINS!\n" << "Your Choice: " << user << "\nComputer's Choice: " << computer << endl;
}
return 0;
}
The variables user and computer are the integer values that I want to convert to a string to display a word. Thank you in advance!
You could make your code clearer by enumerating your choices, but that's up to you. See (http://stackoverflow.com/questions/12183008/how-to-use-enums-in-c) for details.