The world’s Largest Sharp Brain Virtual Experts Marketplace Just a click Away
Levels Tought:
Elementary,Middle School,High School,College,University,PHD
| Teaching Since: | Jul 2017 |
| Last Sign in: | 337 Weeks Ago, 1 Day Ago |
| Questions Answered: | 15833 |
| Tutorials Posted: | 15827 |
MBA,PHD, Juris Doctor
Strayer,Devery,Harvard University
Mar-1995 - Mar-2002
Manager Planning
WalMart
Mar-2001 - Feb-2009
I am having problems with my function returning a winner after I coded the rock scissors and paper function play. I need to complete it ASAP. Thank you.
#include <iostream>
#include <string>
using namespace std;
void play (int winner) {
string p1, p2;
if ((p1 == "paper") || (p2 == "rock")){
return 1; }
else if ((p1 == "rock") || (p2 == "scissors")){
return 1; }
else if ((p1 == "scissors") || (p2 == "paper")){
return 1;
}
}
int main()
{
string p1, p2;
cout << "Play rock, paper, scissorsn";
string goOn = "yes";
while (goOn == "yes") {
cout << "Player 1: ";
cin >> p1;
cout << p1 << endl;
cout << "Player 2: ";
cin >> p2;
cout << p2 << endl;
int winner = play(p1, p2);
if (winner == 0)
cout << "Draw!" << endl;
else if (winner == 1)
cout << "Player 1 wins!" << endl;
else if (winner == 2)
cout << "Player 2 wins!" << endl;
else
cout << "ACK! SOMETHING IS WRONG!" << endl;
cout << "Do you want to continue? (yes or no): ";
cin >> goOn;
cout << goOn << endl;
}
}
I get these compile errors if it helps ...
main.cpp: In function 'void play(int)':
main.cpp:10:11: error: return-statement with a value, in function returning 'void' [-fpermissive]
return 1; }
^
main.cpp:13:14: error: return-statement with a value, in function returning 'void' [-fpermissive]
return 1; }
^
main.cpp:16:14: error: return-statement with a value, in function returning 'void' [-fpermissive]
return 1;
^
main.cpp: In function 'int main()':
main.cpp:32:27: error: cannot convert 'std::__cxx11::string {aka std::__cxx11::basic_string<char>}' to 'int' for argument '1' to 'void play(int)'
int winner = play(p1, p2);
----------- ----------- H-----------ell-----------o S-----------ir/-----------Mad-----------am ----------- Th-----------ank----------- yo-----------u f-----------or -----------you-----------r i-----------nte-----------res-----------t a-----------nd -----------buy-----------ing----------- my----------- po-----------ste-----------d s-----------olu-----------tio-----------n. -----------Ple-----------ase----------- pi-----------ng -----------me -----------on -----------cha-----------t I----------- am----------- on-----------lin-----------e o-----------r i-----------nbo-----------x m-----------e a----------- me-----------ssa-----------ge -----------I w-----------ill----------- be----------- qu-----------ick-----------ly