I am extremely new to c++ and, after spending a few evenings learning the basics, decided to try and code a basic calculator. I got the first part, addition down fairly easily, but am having trouble with subtraction. It isn't making the calculator subtract, but the if then statement that is giving me trouble. Here is my code:
#include <iostream>
usingnamespace std;
//Addition is done...Time to move on to subtraction!
int main ()
{
int start;
cout << "Do you want to: 1)Add 2)Subtract"<<endl;
cin >> start;
if (start == 1);
{
int x;
int y;
int z;
cout << "Add this number:"<<endl;
cin >> x;
cout << "To this number:"<<endl;
cin >> y;
z = (x + y);
cout << "Which equals:"<<z<<endl;
}
elseif (start ==2);
{
int x;
int y;
int z;
cout << "Subtract this number:"<<endl;
cin >> x;
cout << "From this number:"<< endl;
cin >> y;
z = (y - x);
cout << "Which equals:"<<z<<endl;
}
return 0;
}
. The problem seems to be in the "else if (start ==2);". It says "Error: Expected a statement." What does this mean?
I think it has to do with you putting semicolons after the if and else if parenthesis. Take out the semi colons in lines 11 and 24 and tell me if that fixes it.
yeah try removing the two semicolons. Then if it still doesn't work some sucky compilers expect an else statement if you have an else if statement...so if it still doesn't work try adding an else statement.