Rock-Paper-Scissors compiler error

I’ve re-started this challenge a few times but I keep getting a compiler error saying I should have more semicolons in my if statement. I’m sure it’s something syntax related, but I can’t figure it out! I didn’t have this problem in earlier tasks.

rock_paper_scissors.cpp: In function ‘int main()’:
rock_paper_scissors.cpp:29:26: error: expected ‘;’ before ‘{’ token
} else (computer == 3) {

#include <iostream>
#include <stdlib.h>

int main() {
  
  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) ✊\n";
  std::cout << "2) ✋\n";
  std::cout << "3) ✌️\n";

  std::cout << "shoot!\n";
  std::cin >> user;

  if (computer == 1) {
    std::cout << "COMP: ✊\n";
  } else if (computer == 2) {
    std::cout << "COMP: ✋\n";
  } else (computer == 3) {
    std::cout << "COMP: ✌️\n";
  }
}

Hey there @gcullooo and welcome to the forums :slightly_smiling_face:

Your error is resulting from the structure of your if blocks. Remember that an else is supposed to cover all possibilities after the if and else if blocks have been evaluated as false.

However, here on line 29 you are trying to supply a condition to the else.

This error may seem misleading, but it is due to the fact that you are interrupting the else blocks flow with an unknown line of code.

2 Likes

Perfect, thanks! I forgot how else functions. It works now! :grin:

2 Likes