-
July 17th, 2010, 04:37 AM
#1
HELP with Basic else if statment
HI,
Im sure this will be easy for you guys, however it's being annoying me for quite a while now. I have only studyed a couple of hours in C++ in a induction sesision.
ok here is my code:
#include <iostream>
using namespace std;
int main()
{
char op;
int num1;
int num2;
int ans;
cout <<"Enter your first number: ";
cin >> num1;
cout <<"Enter your second number: ";
cin >> num2;
cout << "" << endl;
if (op == '+');
cout << "Add" <<endl;
{
ans = num1 + num2;
cout << "Answer is " << ans << endl;
cout << "" << endl;
}
else if (op == '-');
cout << "Subtract" <<endl;
{
ans = num1 - num2;
cout << "Answer is " << ans << endl;
cout << "" << endl;
}
else if (op == '*');
cout << "Times" <<endl;
{
ans = num1 * num2;
cout << "Answer is " << ans << endl;
cout << "" << endl;
}
else (op == '/');
cout << "Divide" <<endl;
{
ans = num1 / num2;
cout << "Answer is " << ans << endl;
cout << "" << endl;
}
system("PAUSE");
}
Right the problems, i carnt see anthing wrong with it however when i try to run it in Dev-C++ is says there is somthing wrong with my else if statments, however if i replace them with if startments it runs just not the way i want it to.
hope you can help i am very new to C++ so any help will be appreciated.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|