Friends,
I have just begun taking my first C++ class on-line and I am having problems with an if - else error. It is driving me crazy. I am attaching my program and hopefully one of you pros can help me out. I think I'm close. Thanks...
Freddyboy
Code:#include <iostream> #include <cmath> using namespace std; int main() { int num1, num2, answer; char operand; cout << "Please enter a number: "; cin >> num1; cout << "Now enter an operand: "; cin >> operand; cout << "Now enter a second number: "; cin >> num2; if (operand == '+') answer = num1 + num2; cout << "The answer is " << num1 << "+" << num2 << "=" << answer << endl; if (operand == '-') answer = num1 - num2; cout << "The answer is " << num1 << "-" << num2 << "=" << answer << endl; if (operand == '*') answer = num1 * num2; cout << "The answer is " << num1 << "*" << num2 << "=" << answer << endl; if (operand == '/') answer = num1 / num2; cout << "The answer is " << num1 << "/" << num2 << "=" << answer << endl; if (operand == '%') answer = num1 % num2; cout << "The answer is " << num1 << "%" << num2 << "=" << answer << endl; else cout << "An invalid operator was entered" << endl; return 0; }



LinkBack URL
About LinkBacks


