Spam problem
Sep 15, 2014 at 10:33am UTC
In the code everything works fine but at last in line 33 the code say 0 to continue and any key to finish the program while I press and letter the console spam the result I wanted to know how to deal with this and how to fix it.
I beleive its because "num" is integer but I don't know how to deal with it..
Big thank for the one who will help me.. ;)
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
#include <iostream>
using namespace std;
int main()
{
double a, b;
double answer;
int num;
int num1;
do {
cout << "Please enter a number: " ;
cin >> a;
cout << endl << "Please enter a number: " ;
cin >> b;
cout << endl;
cout << "Choose your mathematical operaion:-\n\n1) Addition\n\n2)Subtraction\n " ;
cout << endl << "My choice is: " ;
cin >> num1;
cout << endl;
switch (num1){
case 1:
answer = a + b;
cout << endl << "The result is" << answer << endl << endl;
break ;
case 2:
answer = a - b;
cout << endl << "The result is" << answer << endl << endl;
break ;
default :
cout << "GO LEARN ENGLISH" << endl << endl;
}
cout << "Press any key if you want to finish the program or 0 to continue " ;
cin >> num;
cout << endl;
}while ( num == 0 );
}
Sep 15, 2014 at 10:48am UTC
Change your int num to char, then change that while to while (num=='0' )
Sep 16, 2014 at 1:22pm UTC
I did what you said and yet every key ends the program
any other advices??
Last edited on Sep 16, 2014 at 1:34pm UTC
Sep 16, 2014 at 10:41pm UTC
Any help?
Sep 16, 2014 at 10:50pm UTC
Isn't that what you wanted? Anything but 0 to end the program?
Sep 17, 2014 at 11:20am UTC
And so do "0"
Fixed..
Thanks
Last edited on Sep 17, 2014 at 11:47am UTC
Topic archived. No new replies allowed.