Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

debug this code for me or find the mistake and fix please its C++. #include #include #include using namespace std; int getCompSelection(); int getUserSelection(); void

debug this code for me or find the mistake and fix please its C++.

#include #include #include

using namespace std;

int getCompSelection(); int getUserSelection(); void playResults(int comp, int user, int &wins, int &losses, int &ties); void finalResults(int wins, int losses, int ties);

int main() { int compSelection, userSelection; int wins = 0, losses = 0, ties = 0; char playAgain = 'y';

srand(time(0));

while (playAgain == 'y' || playAgain == 'Y') { compSelection = getCompSelection(); userSelection = getUserSelection();

playResults(compSelection, userSelection, wins, losses, ties);

cout << "Play again? (y or n): "; cin >> playAgain; }

finalResults(wins, losses, ties);

return 0; }

int getCompSelection() { return rand() % 3 + 1; }

int getUserSelection() { int selection; cout << "What is your play? Rock (1), Paper (2), Scissors (3): "; cin >> selection; while (selection < 1 || selection > 3) { cout << "Invalid choice. Please enter 1, 2, or 3: "; cin >> selection; } return selection; }

void playResults(int comp, int user, int &wins, int &losses, int &ties) { switch (user) { case 1: if (comp == 1) { ties++; cout << "You played rock and I played rock" << endl; cout << "The play was a tie" << endl; } else if (comp == 2) { losses++; cout << "You played rock and I played paper" << endl; cout << "Paper covers rock, I win" << endl; } else if (comp == 3) { wins++; cout << "You played rock and I played scissors" << endl; cout << "Rock smashes scissors, you win" << endl; } break; case 2: if (comp == 1) { wins++; cout << "You played paper and I played rock" << endl; cout << "Paper covers rock, you win" << endl; } else if (comp == 2) { ties++; cout << "You played paper and I played paper" << endl; cout << "The play was a tie" << endl; } else if (comp == 3) { losses++; cout << "You played paper and I played scissors" << endl; cout << "Scissors cuts paper, I win" << endl; } break; case 3: if (comp == 1) { losses++;

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

Genetic Databases

Authors: Martin J. Bishop

1st Edition

0121016250, 978-0121016258

More Books

Students also viewed these Databases questions

Question

Question What is a Roth 403 (b) plan?

Answered: 1 week ago

Question

Question Can a Keogh plan fund be reached by the owners creditors?

Answered: 1 week ago