Assignment Instructions

  1. The goal of this program is to practice writing functions in C.
  2. Edit, compile, and run the following program on the UH UNIX shell:
    1. Write a program with a main() function and at least three (3) of your own functions definitions (and corresponding function prototypes and function calls). In other words, you will write four (4) functions - one (1) main() function and three (3) more functions, which are called from the main() function.
    2. Use the C random number generator to create a "rock, paper, scissors" game.
    3. The interface is up to you - just make sure the game is easy to understand.
    4. Include error checking, in case the user enters the wrong number and/or character.
    5. Keep playing until the user enters EOF to quit. EOF ("End of File") is a character that marks the end of a file. To output EOF from the keyboard, press Ctrl-D (which will output "^D" on the screen) on UNIX or Mac, or Ctrl-Z (which will output "^Z" on the screen) on a PC. See example program at: counting.c
    6. Use function getchar() to get one character from the user.
    7. Before ending the program, display the total score of the "rock, paper, scissors" game.
    8. Email your makefile and C program to the instructor, or show it to the instructor in class.
  3. For the submission guidelines and the grading guidelines, see the syllabus.

Example I/O

Welcome to the rock-paper-scissors game!
To quit the game, press Ctrl-D (which will output "^D" on the screen).

Enter 'r', 'p', or 's' for rock, paper, or scissors: r
two rocks, so it's a tie!

Enter 'r', 'p', or 's' for rock, paper, or scissors: p
paper vs. rock, so USER wins!

Enter 'r', 'p', or 's' for rock, paper, or scissors: s
two scissors, so it's a tie!

Enter 'r', 'p', or 's' for rock, paper, or scissors: s
two scissors, so it's a tie!

Enter 'r', 'p', or 's' for rock, paper, or scissors: p
paper vs. scissors, so COMPUTER wins!

Enter 'r', 'p', or 's' for rock, paper, or scissors: r
rock vs. scissors, so USER wins!

Enter 'r', 'p', or 's' for rock, paper, or scissors: x
USER INPUT ERROR

Enter 'r', 'p', or 's' for rock, paper, or scissors: y
USER INPUT ERROR

Enter 'r', 'p', or 's' for rock, paper, or scissors: ^D 

User Wins     Computer Wins     Ties
        2                 1        3

Click to validate the HTML code

Click to validate the CSS code