Question: Write a C program to play a game of hammer, sword, armor against a computer. If both the user and the computer choose the same
Write a C program to play a game of hammer, sword, armor against a computer. If both the user and the
computer choose the same thing, then it is a tie. The program must contain three functions:
1
-
char GetUserSelection(): A function that takes no parameters and returns a char representing
the user
s choice. The choice can either be: A or a for armor, H or h for hammer, S or s for
sword, or Q or q if the user does not want to play (quit)
.
2
-
char GetComputerSelection(): A function that takes no parameters and returns a char
representing the computer
s selection (hammer, sword, armor)
. The computer
s choice is to be
randomly generated (use the random function) Have the system generate a random number
between 0 and 2 where 0 denotes hammer, 1 denotes sword, and 2 denotes armor.
3
-
Int GetWinner(char user_choice, char computer_choice): A function that takes 2 paramters
representing the user
s choice and the computer
s choice and returns
-
1 if the computer wins, 0
if it
s a tie, and 1 if the user wins.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
