i need to keep entering in the terminal
when i put an int in terminal nothings happening, then after a few enter it will show result but the res is wrong
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
|
#include <iostream>
using namespace std;
int main (){
cout << "Calculator 2.0";
char again = 'Y';
while(again == 'y' || again == 'Y'){
double x,y,ans;
int op;
cout << "1.Addition\n";
cout << "2.Substraction\n";
cout << "3.Multiplication\n";
cout << "4.Division\n";
cout << "Enter an operation:";
cin >> op;
cout << "Enter two digits:";
cin >> x >> y;
while(!(cin >> op)){
cout << "Only choose above choices:";
cin.clear();
cin.ignore(100, '\n');
}
while(!(cin >> x >> y)){
cout << "Must be a number:";
cin.clear();
cin.ignore(100, '\n');
}
switch(op){
case 1:
ans = x + y;
cout << x << " + " << y << " = " << ans;
cout << "Calculate again? [Y/N]";
cin >> again;
break;
case 2:
ans = x - y;
cout << x << " - " << y << " = " << ans;
cout << "Calculate again? [Y/N]";
cin >> again;
break;
case 3:
ans = x * y;
cout << x << " * " << y << " = " << ans;
cout << "Calculate again? [Y/N]";
cin >> again;
break;
case 4:
ans = x / y;
cout << x << " / " << y << " = " << ans;
cout << "Calculate again? [Y/N]";
cin >> again;
break;
}
}
}.
| |
Remove your input validation or fix it. It's not doing what you think it is.
Topic archived. No new replies allowed.