Basic IF statement problem for 'Rock Paper Scissors' game

This is a discussion on Basic IF statement problem for 'Rock Paper Scissors' game within the C++ Programming forums, part of the General Programming Boards category; Hi there, I have to make a game of Rock Paper Scissors using the IF statement. Two players. So far ...

1. Basic IF statement problem for 'Rock Paper Scissors' game

Hi there,

I have to make a game of Rock Paper Scissors using the IF statement. Two players.

So far this is what I have :-

Code:
```#include <iostream>
using namespace std;
int main()
{
int playerone;
int playertwo;

cout << "Player 1, please enter '1' for Rock, '2' for Paper or '3' for Scissors and then press Enter ";
cin >> playerone;
cin.ignore();
cout << "Player 2, please enter '1' for Rock, '2' for Paper or '3' for Scissors and then press Enter ";
cin >> playertwo;
cin.ignore();

if (playerone == '1' + playertwo == '2')

{
cout << "Player two wins";

else if (playerone == '1' + playertwo == '3');
cout << "Player one wins";

else
cout << "you made an error";}

cin.get();```
When I enter 1,2,or 3 it just keeps saying 'you made an error", now isn't even compiling as it says "23 expected primary-expression before "else" ".

Buggy.

Thanks for any help.

smiley.jpg

2. >> if (playerone == '1' + playertwo == '2')
You don't use + to combine the expressions. Look up (or remember) how to write a logical AND.

You also have an extra semi-colon that will cause compile errors.

3. You're using incorrect operator + where it isn't supposed to be used and you didn't write that IF statement correct. Perhaps you should read up on +, && and IF statements a little.

4. Code:
```#include <iostream>
using namespace std;
int main()
{
int playerone;
int playertwo;

cout << "Player 1, please enter '1' for Rock, '2' for Paper or '3' for Scissors and then press Enter ";
cin >> playerone;
cin.ignore();
cout << "Player 2, please enter '1' for Rock, '2' for Paper or '3' for Scissors and then press Enter ";
cin >> playertwo;
cin.ignore();

if (playerone == '1' && playertwo == '2');

{
cout << "Player two wins" << endl;

else (playerone == '1' && playertwo == '3');
cout << "Player one wins" endl;

cin.get();
}```
Thanks !

Just added a } at the end, and one further up.

Fails to compile on this line:-

Code:
` else if (playerone == '1' && playertwo == '3');`

5. Look at that line very closely and you will spot the problem (that was also mentioned somewhere in this thread).

Edit: Your edited post has more errors than the original.

6. IF-clause is still incorrect.
Each if should have a starting
Code:
`{`
and and ending
Code:
`}`
(this also includes else if!) (unless you put a single line of code after the IF, in that case you don't need it.
You should not put
Code:
`;`
after IFs either.

7. You're also missing an >> here:
Code:
`cout << "Player one wins" endl;`
 Your program's output might also be easier to read if you printed it more like this:
Code:
```Player 1, please enter
'1' for Rock;
'2' for Paper; or
'3' for Scissors,
and then press Enter```
Just a thought. [/edit]

8. Originally Posted by dwks
You're also missing an >> here:
I believe that should be <<, yes?
Like this
Code:
`cout << "Player one wins" << endl;`

9. Well, yes. I was just testing you.

There are also some logical errors with the program. It reads in two numbers, but compares those numbers to '1' and '2' which are characters.

You have to read in numbers and compare with 1, 2, etc (without quotes); or read in characters and compare with '1', '2', etc (with quotes).