i need help !

hello people i new in c++,i have to program a (rock,scissors,paper)game i have 2 errors with cin
"Error 1 error C2679: binary '>>' : no operator found which takes a right-hand operand of type 'const char [13]' (or there is no acceptable conversion)
Error 2 error C2679: binary '>>' : no operator found which takes a right-hand operand of type 'const char [14]' (or there is no acceptable conversion)"

,anybody can fix it? thank you:))
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
 #include <iostream> 
using namespace std;
const int ROCK = 1;
const int SCISSORS = 2;
const int PAPER = 3;

int main() {
	int x, y;
	cout << " Please enter choice : rock(1) scissors(2) paper(3) or any other number to quit";
	cin >> "first choice">> x;
	cin >> "second choice">> y;
		while (x == y){
		cout << "Draw" << x, y;
	}
	while (x == ROCK){
		if (y ==SCISSORS){ cout << "first player won" << x, y;
		}
		else{ cout << "second player won" << x, y; }
	}
	while (x == SCISSORS){
		if (y == ROCK){ cout << "second player won" << x, y; }
		else{ cout << "first player won" << x, y; }
	}
	while (x == PAPER){
		if (y == ROCK){ cout << "first player won" << x, y; }
		else{ cout << "second player won" << x, y; }
	}
	return 0;
}
Last edited on
 
cin >> "first choice">> x;

You can't do this. cout and cin need to be separate.

1
2
cout << "First choice: ";
cin >> x;

I see that you are using cin to print out onto the console and capture input. I used cout to print out "first choice" then used cin to capture input for x(same goes with y). Also, I put breaks in your while loops so they do not continue forever.

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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
 
#include <iostream>
using namespace std;
const int ROCK = 1;
const int SCISSORS = 2;
const int PAPER = 3;

int main() {
	int x, y;
	cout << " Please enter choice : rock(1) scissors(2) paper(3) or any other number to quit";
	cout << "first choice : "; cin >> x;
	cout << "second choice : "; cin >> y;

    while (x == y)
    {
        cout << "Draw" << x << y;
        break;
    }

	while (x == ROCK){
		if (y ==SCISSORS)
        {
            cout << "first player won " << x << y;
		}
		else if (x == y)
		{
		    cout << "Draw" << x << y;
		    break;
        }
        else
        {
            cout << "second player won " << x << y;
        }
        break;
	}

	while (x == SCISSORS){
		if (y ==PAPER)
        {
            cout << "first player won " << x << y;
		}
		else if (x == y)
		{
		    cout << "Draw" << x << y;
		    break;
        }
        else
        {
            cout << "second player won " << x << y;
        }
        break;
	}

	while (x == PAPER){
		if (y ==ROCK)
        {
            cout << "first player won " << x << y;
		}
		else if (x == y)
		{
		    cout << "Draw" << x << y;
		    break;
        }
        else
        {
            cout << "second player won " << x << y;
        }
        break;
	}

	return 0;
}
Thank you guys ,you are awesome:)))
Topic archived. No new replies allowed.