Unreasonable Error

Im not sure why it comes up with these errors...they dont seem reasonable for me. I am new so I may of skipped something. Can some one tell em why im getting these codes and maybe post a correct code and/or an explination of why it gives me these?

Build Error output:
1>------ Build started: Project: Zachs Calculator, Configuration: Debug Win32 ------
1>Compiling...
1>Clacualtor.cpp
1>c:\users\zach\documents\visual studio 2008\projects\project1\zachs calculator\zachs calculator\clacualtor.cpp(14) : error C2059: syntax error : '<'
1>c:\users\zach\documents\visual studio 2008\projects\project1\zachs calculator\zachs calculator\clacualtor.cpp(17) : error C2181: illegal else without matching if
1>Build log was saved at "file://c:\Users\Zach\Documents\Visual Studio 2008\Projects\Project1\Zachs Calculator\Zachs Calculator\Debug\BuildLog.htm"
1>Zachs Calculator - 2 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

My code:

#include <iostream>
#include <windows.h>
using namespace std;
int main()
{
int op;
cout << "Welcome to Zach's Calcualtor! Customly Built by Zach! Hand Written!\n\n";
cout << "This calulator can manage a few things:\nMulitiplication, Division (With remanders), Addition, and Subtraction\n\n";
cout << "You MUST restart the calcualtor to preform a diffrent operation\n";
cout << "What operation would you like to do?\n\n";
cout << "1=Division 2=Mulitplication 3=Addition 4=Subtraction\n";
cin >> op;
if (op=<2); // Division and Multiplication
{
}
else //Sub and Add
{
}

}


Last edited on
The Syntax error with the < has been resolved, All I need help with is the "illegal else without matching if" Error
an if block goes until the next pair of braces {} or until the next semicolon ;

because you have a semicolon immediately after the if, the if block is completely empty, followed by a pair of braces:

1
2
3
4
5
6
if(foo)
  ;   // the if block ends here
{
  // this is unrelated to the if.  It will run regardless of 'foo'
}
else  // error because it didn't immediately follow an if block 


in short: remove that semicolon:

1
2
3
4
5
if(foo)  // no semicolon here
{
  // now this is the if block
}
else  // now this works 
also you should add a return statement at the end of the function:
return 0;
Well I acculay solved the problem strangely enough, without help. It turns out without ethir of the solutions given. I did it by pressing enter after "else" and nothing else. I didnt have a chance to post it though.
gah?

putting a new line after the else won't do anything. The only way to solve it is to do what I suggested and remove that semicolon.
Topic archived. No new replies allowed.