Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Else If statements unable to compile – "error: expected ';' before '{' token"

I am new. Please excuse me.
When compiling the following code that is entirely ‘if’ statements, the final "else" statement does not work. I receive the error message as mentioned in the title. If I change the final "else" to an "else if" the code will run. This makes no sense to me as I was told that the final statement should just be "else". Thanks for any help.

#include <iostream>
using namespace std;

int main() {
  int menu, number1, number2;
  double sum;

  cout << "1: Addition\n2: Division\n\n";
  cin >> menu;

  if(menu == 1){    //Addition
    cout << "gimme a num: ";
    cin >> number1;
    cout << "gib another: ";
    cin >> number2;
    sum = number1 + number2;
    cout << sum;
  }else(menu == 2){     //division       !THIS IS THE LINE IN QUESTION!
    cout << "gimme a num: ";
    cin >> number1;
    cout << "gib another: ";
    cin >> number2;
    sum = number1 / number2;
    cout << sum;
  }

  return 0;
}

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Remove "(menu == 4)" after that last else.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading