Rock paper scissors

Hi,

I’m trying to make the rock paper scissors game and i got the wrong output for my code and can’t figure out why.

my code: > srand (time(NULL));

int computer = rand() % 3 + 1;

int user = 0;

std::cout << “====================\n”;
std::cout << “rock paper scissors!\n”;
std::cout << “====================\n”;

std::cout << “1) :fist:\n”;
std::cout << “2) :raised_hand:\n”;
std::cout << “3) :v:\n”;

std::cout << "shoot! ";

std::cin >> user;

  if (computer == 1 && user == 1)	{
	std::cout << "Rock vs Rock, Draw!\n";
}

  else (computer == 1 && user == 2);	{
	std::cout << "Paper beats rock, you win!\n";
}

and my output:

wrong%20output

can anyone see from this what’s wrong?

2 Likes

Please see my comments above. Also, as written, your else statement is terminated by the semicolon, and std::cout << "Paper beats rock, you win!\n"; is a statement all on its own. It gets executed every time your code runs. Remember that else statements do not have conditions. If you want to test another condition you need else if (condition) {code block}
Hope this helps!

1 Like

Thanks very much for the response, I was confused I thought else statements had a condition too.
the semicolon was there otherwise it wouldn’t compile, probably because of the if statement :wink:

2 Likes