Question
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
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started