New and needing help to pass class

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;
}
}

if (user == '2')
{

if (user2 == 2)
{
cout << "You tied, scissors vs scissors. " << endl;
cout << endl;
}
else if (user2 == 0)
{
cout << "You lose, rock beats scissors." << endl;
cout << endl;
}
else if (user2 == 1)
{
cout << "You win! scissors beats paper." << endl;
cout << endl;
}

}

return 0;

}


you need to have an int main() function in there somewhere.
Last edited on
Here's a simple version of the program to use as a reference.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include <iostream>
using namespace std;

int rockPaperScissors(char user1, char user2)
{
    if ((user1 == '0' && user2 == '1') ||
        (user1 == '2' && user2 == '0') ||
        (user1 == '1' && user2 == '2'))
       return 2;


    else if ((user1 == '1' && user2 == '0') ||
             (user1 == '0' && user2 == '2') ||
             (user1 == '2' && user2 == '1'))
      return 1;

   else
    return 0;
}

int main()
{
    char user1, user2;

    cout << "This is the game rock, paper, scissors." << endl;

       cout << "User 1: Choose 0 for rock, 1 for paper, 2 for scissors or Q to quit:" << endl;
       cin >> user1;

       if (user1 == 'q' || user1 == 'Q')
          return 0;

       cout << "User 2: Choose 0 for rock, 1 for paper, 2 for scissors or Q to quit:" << endl;
       cin >> user2;

       if (user2 == 'q' || user2 == 'Q')
          return 0;

    if (rockPaperScissors(user1, user2) != 0)
        cout << "User " << rockPaperScissors(user1, user2) << " wins!\n";

    else
      cout << "Tie!";

   return 0;
}
Last edited on
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.
On the right of the reply box, the button with <> will add code tags to the text. You can also type it manually
Last edited on
Topic archived. No new replies allowed.