Hey everyone. I'm in a C++ class that I'm currently failing. The teacher doesn't believe in helping her students because she believes they will figure out how to do everything on there own. We have an assignment to do a game of rock paper scissors. This is what I have so far, but with my very limited knowledge, I can't get it to work. If anyone could help me, then it would be greatly appreciated.
#include <iostream>
#include <ctime>
#include <cstdlib>
using namespace std;
char rockPaperScissors()
{char user2;
{
char user = 'Q';
while (true)
{
cout << "This is the game rock, paper, scissors." << endl;
again:
cout << "Choose: (0 for rock, 1 for paper, 2 for scissors or Q to quit):" << endl;
cin >> user;
cin.ignore(1000, 10);
if (user == '0' || user == '1' || user == '2') return user;
if (user == 'Q' || user == 'q') break;
}
{
cout << "Choose: (0 for rock, 1 for paper, 2 for scissors or Q to quit):" << endl;
cin >> user2;
cin.ignore(1000, 10);
if (user2 == '0' || user2 == '1' || user == '2') return user;
if (user2 == 'Q' || user2 == 'q')
cout << user << " This was not a valid choice, please select again. " << endl;
goto again;
}
return 'q';
}
{
srand(time(0));
while (true)
{
char user;
user = rockPaperScissors();
if (user == 'Q' || user == 'q') break;
if (user == '0')
{
if (user2 == 0)
{
cout << "You tied, rock vs rock. " << endl;
cout << endl;
}
else if (user2 == 1)
{
cout << "You lose, paper beats rock." << endl;
cout << endl;
}
else if (user2 == 2)
{
cout << "You win! rock beats scissors." << endl;
cout << endl;
}
}
if (user == '1')
{
if (user2 == 1)
{
cout << "You tied, paper vs paper. " << endl;
cout << endl;
}
else if (user2 == 0)
{
cout << "You win! paper beats rock. " << endl;
cout << endl;
}
else if (user2 == 2)
{
cout << "You lose, scissors beats paper." << endl;
}
}
Thanks a ton guys! I really appreciate the kindness. I'll see what I can come up with. Also, how do you place code the way you did within the blue box? I was aware of it, but I have no idea how to do that.