Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Below code is a rock paper scissor game for C++ I don't know why my 1.rock choice doesn't display and breaks out the code need

Below code is a rock paper scissor game for C++

I don't know why my 1.rock choice doesn't display and breaks out the code

need help asap please and thank you!

____________________________

#include

#include

#include

#include

using namespace std; //libraries

void displayMenu()

{

cout<<"1. Rock"<

cout<<"2. Paper"<

cout<<"3. Scissors"<

cout<<"Enter your choice (1, 2, 3):";

}

int getUserInput()// the player if choosing range outside num

{

int choice;

//const choice;

while(true)

{

cin>>choice;

if(choice<1 || choice>3)

{

cout<<"Invalid choice. Choose from menu displayed "; //setting error message

}

else

{

break;

}

}

return choice; //.

}

int generateComputerChoice() //computer turn will not show here

{

return rand()%3+1; //equation to randimize the choice

}

void displayChoice(int choice)

{

if(choice==1)

{

cout<<"Rock"<

}

else if(choice==2)

{

cout<<"Paper"<

}

else if(choice==3)

{

cout<<"Scissors"<

}

cout<

}

void selectWinner(int user, int computer) //void

{

if(user==2 && computer==1 || user==3 && computer==2||user==1 && computer==3) //the possibe winning choice

{

cout<<"User wins"<

}

else if(user==computer)

{

cout<<"It's a Tie"<

}

else

{

cout<<"Computer wins"<

}

} //all possible inputs from both user and computer

int main()

{

while(true)

{

displayMenu();

int choice;

int userChoice = getUserInput();

if(userChoice== choice<1 || choice>3)

{

break;

}

int computerChoice = generateComputerChoice();

cout<<"User choose : "; displayChoice(userChoice);

cout<<"Computer choose : "; displayChoice(computerChoice);

selectWinner(userChoice,computerChoice);

cout<<"---------------"<

}

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Expert Oracle Database Architecture

Authors: Thomas Kyte, Darl Kuhn

3rd Edition

1430262990, 9781430262992

More Books

Students also viewed these Databases questions

Question

What is Centrifugation?

Answered: 1 week ago

Question

To find integral of ?a 2 - x 2

Answered: 1 week ago

Question

To find integral of e 3x sin4x

Answered: 1 week ago

Question

To find the integral of 3x/(x - 1)(x - 2)(x - 3)

Answered: 1 week ago

Question

What are Fatty acids?

Answered: 1 week ago