Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I'm having troubles running this program, why can't I get this c++ code to run? I'm getting 60 error messages. #include stdafx.h #include #include #include

I'm having troubles running this program, why can't I get this c++ code to run? I'm getting 60 error messages.

#include "stdafx.h" #include #include #include using namespace std; // functions prototypes void displayGameDetails(); void playGame(); string getComputerChoice(); string getUserChoice(); string getChoiceAsString(int); void displayChoices(string, string); string findWinner(string, string); // start main function int main() { Call the displayGameDetails() function to display the rules of the game. // get the computer choice for the game displayGameDetails(); Call the playGame() function to find and display the winner of Rock, Paper, Scissors game. // find and display the winner of the game playGame(); // pause the system for a while system("pause"); return 0; } // end of main function

// displayGameDetails function defintion void displayGameDetails() { // display the game details cout << " Rock, Paper, Scissors Game " << endl; cout << "------------------------------" << endl; cout << "Rules to decide a winner:" << endl; cout << "Rock can smash Scissor. Here, the player who chooses Rock is the winner." << endl; cout << "Paper can wrap Rock. Here, the player who chooses Paper is the winner." << endl; cout << "Scissor can cut Paper. Here, the player who chooses Scissor is the winner." << endl; cout << "Both players choose the same choice. Here, both players must play the game again." << endl; } // end of displayGameDetails function

// playGame function definition void playGame() { // local variables string computerChoice; string userChoice; string gameWinner; Call the computerChoice() function to get the computer choice for the game. // get the computer choice for the game computerChoice = getComputerChoice(); Call the getUserChoice() function to get the user choice for the game. // get the user choice for the game userChoice = getUserChoice(); Call the displayChoices() function to display the computer choice and the user choice for the game. /* display the computer choice and the user choice for the game */ displayChoices(computerChoice, userChoice); Call the findWinner() function to get the winner of the game. /* get the winner of the game */ gameWinner = findWinner(computerChoice, userChoice); Display the winner of the Rock, Paper, and Scissors game. // display the winner of the game if (gameWinner != "") cout << "The winner of this game is " << gameWinner << endl; } // end of playGame function

// getComputerChoice function definition string getComputerChoice() { // local variables int comp; string cmpChoice; // get the current time in the system unsigned seedTime = time(0); /* call the predefined srand function to generate a different random number */ srand(seedTime);

// generate a random number as the computer choice comp = 1 + rand() % 3; // get the computer choice as string cmpChoice = getChoiceAsString(comp); // return the computer choice return cmpChoice; } // end of getComputerChoice function

// getUserChoice function definition string getUserChoice() { // local variables int usr; string usrChoice; // display the menu for the user cout << " The computer has chosen one choice." << endl; cout << " Now the user has to choose one of the following." << endl; cout << "1. Rock" << endl; cout << "2. Paper" << endl; cout << "3. Scissor" << endl; // prompt the user to enter his or her choice cout << "Enter the user choice: "; cin >> usr; // verify whether the choice is 1 or 2 or 3 while (usr != 1 && usr != 2 && usr != 3) { // prompt the user to enter his or her choice cout << "Enter 1 or 2 or 3 only: "; cin >> usr; } // end while

// get the user choice as string usrChoice = getChoiceAsString(usr); // return the user choice return usrChoice; } // end of getUserChoice function

// getChoiceAsString function definition string getChoiceAsString(int choice) { // return the corresponding name of the choice if (choice == 1) return "Rock"; else if (choice == 2) return "Paper"; else // choice == 3 return "Scissor"; } // end of getChoiceAsString function

// displayChoices function definition void displayChoices(string comp, string usr) { // display the computer choice cout << " The computer choice: " << comp << endl; // display the user choice cout << "The user choice: " << usr << endl; } // end of displayChoices function

// findWinner function definition string findWinner(string comp, string usr) { // local variables string computer = "Computer"; string user = "User"; string winner; if (comp == "Rock" && usr == "Scissor") winner = computer; else if (comp == "Rock" && usr == "Paper") winner = user; else if (comp == "Paper" && usr == "Rock") winner = computer; else if (comp == "Paper" && usr == "Scissor") winner = user; else if (comp == "Scissor" && usr == "Paper") winner = computer; else if (comp == "Scissor" && usr == "Rock") winner = user; else { // display the message as game drawn cout << " Game is drawn." << endl; cout << "Play again" << endl; cout << "-----------" << endl; // call the playGame function to play again playGame(); } // return the winner of the game return winner; } // end of findWinner function

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

DATABASE Administrator Make A Difference

Authors: Mohciine Elmourabit

1st Edition

B0CGM7XG75, 978-1722657802

More Books

Students also viewed these Databases questions

Question

4. What will the team agreement contain?

Answered: 1 week ago

Question

What were the issues and solutions proposed by each team?

Answered: 1 week ago