Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Question: I need help changing the the following program with these changes; This is a C++ program. we can not use break, continue or goto.

Question: I need help changing the the following program with these changes; This is a C++ program. we can not use break, continue or goto. "Declare One enum MOVE and use it for both the computer move and the user move. Rewrite the validation in getUserMove to eliminate the endless loop and the multiple return statements. use a static_cast to convert the random number into a Move (rather than an if statement) in getComputerMove. Eliminate the infinite loop in main. Eliminate the endless loop in playAgain." #include  using namespace std; //declaration enum ComputerMove { Rock, Paper, Scissor}; enum UserMove { rock, paper, scissor}; //function void showInstructions() { cout<<"------Welcome to Rock Paper Scissor game------ "; cout<<"User should enter R or r for Rock P or p for Paper S or s for Scissor "; } //function UserMove getUserMove() { char c; while(1) { cout<<"Your Move:"; cin>>c; if(c=='R' || c=='r') return rock; else if(c=='P' || c=='p') return paper; else if(c=='S' || c=='s') return scissor; else cout<<"Enter valid move "; } } //function ComputerMove getComputerMove() { int n = rand()%3; if(n==0) return Rock; if(n==1) return Paper; return Scissor; } //function void getWinner(UserMove u,ComputerMove c) { if(u==c) cout<<"It's a tie!! "; else if(u==0 && c==2) cout<<"You won!! "; else if(u==1 && c==0) cout<<"You won!! "; else if(u==2 && c==1) cout<<"You won!! "; else cout<<"Computer won!! "; } //function bool playAgain() { char c; while(1) { cout<<"Do you want to play again?(y/n):"; cin>>c; if(c=='Y' || c=='y') return true; else if(c=='N' || c=='n') return false; else cout<<"Enter valid move!! "; } } //main function int main() { //infininte loop while(1) { //calling functions showInstructions(); enum ComputerMove c = getComputerMove(); enum UserMove u = getUserMove(); getWinner(u,c); if(!playAgain()) exit(0); } return 0; }

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

Data And Databases

Authors: Jeff Mapua

1st Edition

1978502257, 978-1978502253

More Books

Students also viewed these Databases questions

Question

Why is spoofing a significant risk in e-business?

Answered: 1 week ago

Question

Has the priority order been provided by someone else?

Answered: 1 week ago

Question

Explain the function and purpose of the Job Level Table.

Answered: 1 week ago