It's just a little nooby problem. In my book it said to try and design a program that would take two numbers and add or subtract them (With input from the user). Anyway this is what I tried to do:
The problem is when you try and select whether it's plus or minus it just loops even if you select + or -...Code:void main() { int no1, no2; char plusminus; cout << "\n- Please enter 2 integers to be added or subtracted -"; cout << "\n\nNumber 1: "; cin >> no1; while(plusminus != '+' || plusminus != '-') { cout << "\n\nWould you like to add or subtract? (+/-): "; cin >> plusminus; switch(plusminus) { case '+': plusminus = '+'; break; case '-': plusminus = '-'; break; default: cout << "\n\nERROR: That is not an option.\n"; } } cout << "\n\nNumber 2: "; cin >> no2; if(plusminus == '-') cout << endl << no1 << " " << plusminus << " " << no2 << " = " << no1 - no2; else cout << endl << no1 << " " << plusminus << " " << no2 << " = " << no1 + no2; }
Thanks very much if you can help.
-Marlon



LinkBack URL
About LinkBacks



). But the reason I did the '||' instead of the '&&' is because I read in the book that '&&' would mean 'and'.
I knew there had to be a simpler solution... Thank you very much for showing it to me