This is my code where i am having errors:
#include <iostream>
#include <string>
#include <ctime>
#include <cstdlib>
namespace Action
{
enum Shape { ROCK, PAPER, SCISSORS, INVALID_SHAPE };
Shape charToShape(char selection);
bool validShape(char selection);
string shapeToString(Shape object); <--------[ERROR ON THIS LINE]
Shape winningShape(Shape shape1, Shape shape2);
}
string Action::shapeToString(Action::Shape object) [ERROR HERE ON THIS LINE]
{
// Return the name of the shape.
switch (object)
{
case Action::ROCK:
return "Rock";
case Action::PAPER:
return "Paper";
case Action::SCISSORS:
return "Scissors";
default:
return "Unknown Type";
}
}
GameOutcome determineGameOutcome(Action::Shape player, Action::Shape computer)
{
Action::Shape winnerObject;
GameOutcome winner;
// Check for a tie
if (player == computer)
{
winner = TIE;
std::cout << "Both players selected " << shapeToString(player) << ".\n"; [ERROR HERE ON shapeToString}
}
else // See who won
{
winnerObject = winningShape(player, computer);
//Output each player's choice
std::cout << "The player selected " << shapeToString(player); [ERROR HERE ON shapeToString]
std::cout << " and the computer selected " << shapeToString(computer) [ERROR HERE ON shapeToString]
<< ".\n";
//Decide the winner
if (player == winnerObject)
{
winner = WIN;
}
else if (computer == winnerObject)
{
winner = LOSS;
}
}
return winner;
}
This is the compiler error message:
RockPaperScissors.cpp:19:2: error: 'string' does not name a
type; did you mean 'stdin'?
string shapeToString(Shape object);
^~~~~~
stdin
RockPaperScissors.cpp:163:1: error: 'string' does not name a type;
did you mean 'stdin'?
string Action::shapeToString(Action::Shape object)
^~~~~~
stdin
RockPaperScissors.cpp: In function 'GameOutcome
determineGameOutcome(Action::Shape, Action::Shape)':
RockPaperScissors.cpp:213:44: error: 'shapeToString' was not
declared in this scope
std::cout << "Both players selected " <<
shapeToString(player) << ".\n";
^~~~~~~~~~~~~
RockPaperScissors.cpp:220:42: error: 'shapeToString' was not
declared in this scope
std::cout << "The player selected " <<
shapeToString(player);
Resolved the errors which you specified. Actually the reason is string is used as "std::string" but instead you have directly used as "string" due to which it showed error. So, you can use as "std::string" or you can mention "using namespace std" at beginning and then use as "string" then also no issue.
In the corrected one, I used "std::string" which is as follows :-
#include
<iostream>
#include <string>
#include <ctime>
#include <cstdlib>
namespace Action
{
enum Shape { ROCK, PAPER, SCISSORS, INVALID_SHAPE };
Shape charToShape(char selection);
bool validShape(char selection);
std::string shapeToString(Shape object);// <--------[ERROR ON THIS LINE]
Shape winningShape(Shape shape1, Shape shape2);
}
std::string Action::shapeToString(Action::Shape
object)
{
// Return the name of the shape.
switch (object)
{
case Action::ROCK:
return "Rock";
case Action::PAPER:
return "Paper";
case Action::SCISSORS:
return "Scissors";
default:
return "Unknown Type";
}
}
GameOutcome determineGameOutcome(Action::Shape player, Action::Shape computer)
{
Action::Shape winnerObject;
GameOutcome winner;
// Check for a tie
if (player == computer)
{
winner = TIE;
std::cout << "Both players selected " << shapeToString(player) << ".\n";
}
else // See who won
{
winnerObject = winningShape(player, computer);
//Output each player's choice
std::cout << "The player selected " << shapeToString(player);
std::cout << " and the computer selected " << shapeToString(computer) << ".\n";
//Decide the winner
if (player == winnerObject)
{
winner = WIN;
}
else if (computer == winnerObject)
{
winner = LOSS;
}
}
return winner;
}
This is my code where i am having errors: #include <iostream> #include <string> #include <ctime> #include...
How to call a function in another function?C++ Project assistance. In the Project I am attempting to pass getOutcome into runGame to attempt to figure out who would win. Upon trying I get an error that getOutcome isn't in scop of runGame. The & symbols were my last attempt at trying to pass it, I do see it is wrong, and any help that can help me with just that is very appreciated. #include <iostream> #include <fstream> #include <string> #include...
PLEASE INCLUDE SAW-PROMPTS FOR 2 PLAYERS NAMES(VALIDATE NAMES). SHOW MENU (PLAYER MUST SELECT FROM MENU B4 THE GAME STARTS 1=PLAY GAME, 2=SHOW GAME RULES, 3=SHOW PLAYER STATISTICS, AND 4=EXIT GAME WITH A GOODBYE MESSAGE.) PLAYERS NEED OPTION TO SHOW STATS(IN A DIFFERNT WINDOW-FOR OPTION 3)-GAME SHOULD BE rock, paper, scissor and SAW!! PLEASE USE A JAVA GRAPHICAL USER INTERFACE. MUST HAVE ROCK, PAPER, SCISSORS, AND SAW PLEASE This project requires students to create a design for a “Rock, Paper, Scissors,...
Can someone help run this and fix a small error I have when I run this. I get a constant variable error on line 62. I have a constant variable though and I'm sure what to change. I use Visual Basic 2017 as well for any of those wondering. Please help and thanks in advance #include <ctime> #include <iostream> #include <random> #include <string> using namespace std; int main() { const int paper = 0, rock = 1, scissors = 2;...
It's writing a simple rock paper scissors game strictly following the instructions. INSTRUCTIONS: If the user selects 'p': 1. First the program should call a function named getComputerChoice to get the computer's choice in the game. The getComputerChoice function should generate a random number between 1 and 3. If the random number is 1 the computer has chosen Rock, if the random number is 2 the user has chosen Paper, and if the random number is 3 the computer has...
IN JAVA. Write a program that lets the user play the game of Rock, Paper, Scissors against the computer. The program should work as follows. When the program begins, a random number in the range of 1 through 3 is generated. If the number is 1, then the computer has chosen rock. If the number is 2, then the computer has chosen paper. If the number is 3, then the computer has chosen scissors. Don’t display the computer’s choice yet....
(Java) Write a program that lets the user play the game of Rock, Paper, Scissors against the computer. The program should work as follows. When the program begins, a random number in the range of 1 through 3 is generated. If the number is 1, then the computer has chosen rock. If the number is 2, then the computer has chosen paper. If the number is 3, then the computer has chosen scissors. Don’t display the computer’s choice yet. The...
Use Dev C++ for program and include all of the following. Im
lost.
Make sure the user enters a letter of R, P, or S and the
computer generates a number between 0-2 and changes that number to
a letter of R, P or S, using a switch. Make sure the user knows why
he/she has won or lost – print a message like “Paper covers Rock”
or “Scissors cuts Paper”.
Ask the user how many times he/she wants to...
i have created a program for a game of rock, paper, scissors but i must make it run more than once in some kind of loop. i want to add a function named runGame that will control the flow of a single game. The main function will be used to determine which game mode to initiate or exit program in Player vs. Computer, the user will be asked to enter their name and specify the number of rounds for this...
I need help finding 7 errors in the following python code. Please provide indentation in your response. totalRounds = 0 humanWins = 0 humanLosses = 0 humanTies = 0 computerWins = 0 computerLosses = 0 computerTies = 0 uc = 0 cc = 0 rndNbr = 0 print('Welcome to the Rock-Paper-Scissors Game!!') print('Have fun and good luck.\n') totalRounds = int(input('Please enter the number of rounds you must need to win the match:')) while humanWins != totalRounds or computerWins != totalRounds:...
The code will not run and I get the following errors in Visual Studio. Please fix the errors. error C2079: 'inputFile' uses undefined class 'std::basic_ifstream<char,std::char_traits<char>>' cpp(32): error C2228: left of '.open' must have class/struct/union (32): note: type is 'int' ): error C2065: 'cout': undeclared identifier error C2065: 'cout': undeclared identifier error C2079: 'girlInputFile' uses undefined class 'std::basic_ifstream<char,std::char_traits<char>>' error C2440: 'initializing': cannot convert from 'const char [68]' to 'int' note: There is no context in which this conversion is possible error...