Question

Write this program using C++ , (Rock, Paper, Scissors Game – Page 373) This programming assignment...

Write this program using C++ ,

(Rock, Paper, Scissors Game – Page 373)

This programming assignment is from the textbook with some slight modifications and clarifications.

Here is what I am going to except from you. Your program should include at least the following functions:

  • getComputerGuess(): this function should return a random value generated by the computer using rand function (read more about random numbers in Chapter 3 pages 126 – 128).
  • getUsersChoice(): this function will ask the user to enter a choice using a menu. It then returns the user’s selected choice. Here is the menu:

“1) Rock 2)Paper 3) Scissors 4) Quit”

You should allow the game to keep playing until the user decides to quit, that’s when the user chooses 4 from the menu.

  • findTheWinner(int, int): this function has two parameters (one is the user’s choice and the other one is the computer’s randomly generated choice). Based on the passed arguments the function should display the user’s choice, the computer’s choice and the winner.

Here is a sample run of the program:

Game Menu

---------

1) Rock

2) Paper

3) Scissors

4) Quit

Enter your choice: 3

You selected: Scissors

The computer selected: Rock

Computer win! Rock smashes scissors.

Game Menu

---------

1) Rock

2) Paper

3) Scissors

4) Quit

Enter your choice:

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include <iostream>
#include <cmath>
#include <time.h>
#include <cstdlib>
using namespace std;

int getComputerGuess();
int getUserChoice();
void findTheWinner(int user,int comp);
int win = 0;
int tie = 0;
int lose = 0;
int main(){

char ch;
// using do-while loop for
do{
cout << "--------------------------------------" << endl;
cout << "-- Welcome to play Rock, Paper and Scissors Game! --" << endl;
cout << "--------------------------------------" << endl;
int cguess =getComputerGuess();
int choice=getUserChoice();
if(choice>=4)
ch='n';
else{
findTheWinner(choice,cguess);
cout << "Would you like to play again? Y/N" << endl;
cin >> ch;
}
// system("CLS");
}while(ch == 'Y' || ch == 'y');
cout<<"-----Total Games Results--------"<<endl;
cout << "Wins: " << win << endl;
cout << "Ties:" << tie << endl;
cout << "Losses:" << lose << endl;
return 0;
}
int getComputerGuess()
{
return rand() % 3 + 1;
}
int getUserChoice()
{
int num;
cout << "Press 1 for Rock, 2 for Paper, 3 for Scissors 4 for Quit: " << endl;
cin >> num;
return num;
}
void findTheWinner(int uCode,int cCode )
{
if(uCode == 1 && cCode == 1){
cout << "User Choice: Rock \tComputer Choice: Rock \tResult : Tie!" << endl;
tie++;
}
else if(uCode ==1 && cCode== 2){
cout << "User Choice: Rock\tComputer Choice: Paper \tResult: Computer wins!." << endl;
lose++;
}
else if(uCode == 1 && cCode == 3){
cout << "User Choice: Rock \tComputer Choice: Scissors \tResult: you win!" << endl;
win++;
}
else if(uCode == 2 && cCode == 1){
cout << "User Choice: Paper \tComputer Choice: Rock\tResult: you win!" << endl;
win++;
}
else if(uCode == 2 && cCode == 2){
cout << "User Choice: Paper \tComputer Choice: Paper\tResult: Tie!" << endl;
tie++;
}
else if(uCode == 2 && cCode == 3){
cout << "User Choice: Paper\tComputer Choice: Scissors\tResult: Computer wins!" << endl;
lose++;
}
else if( uCode == 3 && cCode == 1){
cout << "User Choice: Scissors\tComputer Choice: Rock\tResult: computer wins!" << endl;
lose++;
}
else if( uCode == 3 && cCode == 2){
cout << "User Choice: Scissors\tComputer Choice: Paper\tResult: you win!" << endl;
win++;
}
else if(uCode == 3 && cCode == 3){
cout << "User Choice: Scissors\tComputer Choice:Scissors\tResult: Tie!" << endl;
tie++;
}
else{
cout << "You didn't select 1, 2, or 3" << endl;
}
}

Add a comment
Know the answer?
Add Answer to:
Write this program using C++ , (Rock, Paper, Scissors Game – Page 373) This programming assignment...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • (c++ only)Write a program that lets the user play the game of Rock, Paper, Scissors against...

    (c++ only)Write a program that lets the user play the game of Rock, Paper, Scissors against the computer. The program should work as follows: When the program begins, the user enters his or her choice of “rock”, “paper”, or “scissors” at the keyboard using a menu in a function, userChoice, that returns a character. Next, there should be a function, computerChoice, that generates the computer’s play. A random number in the range of 1 through 3 is generated. If the...

  • C++ Part 2: Rock Paper Scissors Game Write a program that lets the user play this...

    C++ Part 2: Rock Paper Scissors Game Write a program that lets the user play this game against the computer. The program should work as follows: When the program begins, a random number between 1 and 3 is generated. If the number is 1, the computer has chosen rock. If the number is 2, the computer has chosen paper. If the number is 3, the computer has chosen scissors. Don't display the computer's choice yet. Use a menu to display...

  • IN JAVA. Write a program that lets the user play the game of Rock, Paper, Scissors...

    IN JAVA. Write a program that lets the user play the game of Rock, Paper, Scissors against the computer. The program should work as follows. When the program begins, a random number in the range of 1 through 3 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. Don’t display the computer’s choice yet....

  • Write C++ program, program should include at least the following functions:  getComputerGuess(): this function should...

    Write C++ program, program should include at least the following functions:  getComputerGuess(): this function should return a random value generated by the computer using rand function ( read more about random numbers in Chapter 3 pages 126 – 128 ).  getUsersChoice(): this function will ask the user to enter a choice using a menu. It then returns the user’s selected choice. Here is the menu: “1) Rock 2)Paper 3) Scissors 4) Quit” You should allow the game to...

  • (Java) Write a program that lets the user play the game of Rock, Paper, Scissors against...

    (Java) Write a program that lets the user play the game of Rock, Paper, Scissors against the computer. The program should work as follows. When the program begins, a random number in the range of 1 through 3 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. Don’t display the computer’s choice yet. The...

  • Write a Python program (using python 3.7.2) that lets the user play the game of Rock,...

    Write a Python program (using python 3.7.2) that lets the user play the game of Rock, Paper, Scissors against the computer. The program should work as follows. 1. When the program begins, a random number in the range of 1 through 3 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. (Don’t display the...

  • In JAVA Chapter 5Assignment(Rock, Paper, Scissors)–20pointsYour goal is towrite a program that lets the user play...

    In JAVA Chapter 5Assignment(Rock, Paper, Scissors)–20pointsYour goal is towrite a program that lets the user play the game of Rock, Paper, Scissors against the computer.Your program should have the following: •Make the name of the project RockPaperScissors•Write a method that generates a random number in the range of 1 through 3. The randomly generated number will determine if the computer chooses rock, paper, or scissors. If the number is 1, then the computer has chosen rock. If the number is...

  • C++ You are asked to implement scissors-rock-paper game where the players are a computer and a...

    C++ You are asked to implement scissors-rock-paper game where the players are a computer and a user. The player that wins 3 hands successively is the winner of the game. Your program should prompt the user with a message at the beginning of each hand to enter one of scissors, rock or paper. If the user’s entry is not valid, i.e. entry is neither scissors, rock, nor paper, your program throws a message to the user to enter a valid...

  • Using python 3.7.3 Challenge: Rock, Paper, Scissors GamePDF Description: Create a menu-driven rock, paper, scissors game...

    Using python 3.7.3 Challenge: Rock, Paper, Scissors GamePDF Description: Create a menu-driven rock, paper, scissors game in Python 3 that a user plays against the computer with the ability to save and load a game and its associated play statistics. Purpose: The purpose of this challenge is to assess the developer’s ability to create an interactive application with data persistence in Python 3. Requirements: Create a Rock, Paper, Scissors game in Python named rps.py according to the requirements specified in...

  • In python language Write a program that lets the user play the game of Rock, Paper,...

    In python language Write a program that lets the user play the game of Rock, Paper, Scissors against the computer. The program should work as follows: 1. When the program begins, a random number in the range of 1 and 3 is generated. 1 = Computer has chosen Rock 2 = Computer has chosen Paper 3 = Computer has chosen Scissors (Dont display the computer's choice yet) 2. The user enters his or her choice of “Rock”, “Paper", “Scissors" at...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT