// my first program in C++ (calculator)
// loop bug !
#include <iostream>
usingnamespace std;
int main ()
{
int response;
int select;
int a, b;
do
{
system ("cls"); // its here just because of the loop
cout << "Choose two number to calculate, separated them whit a blank space, then press [enter]." << endl;
cin >> a >> b;
cout << "Do you want to ...\n" << endl;
cout << "1. Add!\n" << endl;
cout << "2. Substract!\n" << endl;
cout << "3. Multiply!\n" << endl;
cout << "4. Divide!\n" << endl;
cout << "Specify operation by selecting right number then pressing [enter].\n\n";
cin >> select;
cout << "=" <<endl;
switch(select)
{
case 1: cout << a + b << endl; break;
case 2: cout << a - b << endl; break;
case 3: cout << a * b << endl; break;
case 4: cout << a / b << endl; break;
default: cout <<"Invalid operation!\n";
}
//here start the problem. the calculator will infinite loop last operation
//ask'ed to the program ( if " y " is pressed ).
cout << "Press y to continue or n to exit.\n";
cin >> response;
}
while (response);
system ("paused"); // i use it just because its the only way i know
return 0;
}
the program work well when it come to calculate but if " y " is pressed it WILL go on a infinite loop :(