Project 4: Rock, Paper, Scissors

Due: 11:59 pm Sunday, Feb. 12

Points Possible: 100

Late Penalty: 20 point deduction for each 24 hour late period

Submit: name the program project4.cpp and put it in your Dropbox Projects folder.

Concentration: Defining functions according to pre- and post-conditions.

Summary:

 

Write a program that lets the user play the game of Rock, Paper, Scissors against the computer.  To earn a C (70-79) , the program should work as follows:

á      When the program begins, a random number in the range of 1 – 3, inclusive, is generated.  If the number is 1, then the computer has chosen Rock; if the number is 2, then the computer has chosen Paper; if the number is 3, then the computer has chosen Scissors. Do not display the computerÕs choice until after the user has chosen.

á      The user enters his or her choice at the keyboard.  You may handle this however you prefer.  Perhaps you want to present them with a menu, and ask them to enter 1 for Rock, 2 for Paper, and 3 for Scissors.  Or, maybe you want them to enter r, p, or s for their choice.  A less desirable way would be for the user to enter ÒrockÓ, etc., because of the typing involved.  Simple is better.

á      The computerÕs choice is displayed.

á      The winner is selected according to the following rules:

o   Rock smashes scissors

o   Scissors cuts paper

o   Paper covers rock

o   If both players make the same choice, the game must be played until a winner is determined.

á      The result is printed to the screen.

 

Divide the program into functions that complete each major task.  You will need the following functions:

 

int generateRandom();
//Postcondition:  a random integer between 1 and 3, inclusive,

//    has been returned.

 

void displayComputerChoice(int choice);

//Precondition:  choice is either 1, 2, or 3

//Postcondition:  If choice was 1, ÒRockÓ was printed; if choice was

//    2, ÒPaperÓ was printed; if choice was 3, ÒScissorsÓ

// was printed.

 

                                                                                            

int determineWinner(int computer_choice, int user_choice);

//Precondition: computer has been assigned a random choice, user has

//    entered choice from keyboard

//Postcondition: If computer had the same value as user (made the

//    same choice) 0 has been returned.  Otherwise, the winner has

//    been determined according to the rules; 1 has been returned if

//    the winner was the computer; 2 has been returned if the

//    winner was the user.

 

 

To earn a B(80-89) add the ability to play more than one game.  After each game, give the user the option to play again or quit.

 

To earn an A(90-99) add the ability to determine and print the percentage of  games in which the computer and the user both chose the same object.  This should be displayed when the user no longer wants to play.

 

More Challenging:

According to this video clip from season 2 of The Big Bang Theory, a better way to determine a winner is by using 2 additional objects.  So the game is Rock, Paper, Scissors, Lizard, Spock.

 http://youtu.be/Kov2G0GouBw

Change the game to allow for these 5 choices.  Compute the percentage of games in which both chose the same object.  How does this compare to Rock, Paper, Scissors?