25 января 2016 г.

калькулятор

double a, b, res;
int answer;
cout << "Welcome. Calc v1" << endl;
cout << "1 - (+)" << endl;
cout << "2 - (-)" << endl;
cout << "3 - (*)" << endl;
cout << "4 - (/)" << endl;
cout << "0 - (exit)" << endl;
cin >> answer;

switch (answer)
{
case 0:
exit(0);
break;
case 1:
cout << "Enter first number" << endl;
cin >> a;
cout << "Enter second number" << endl;
cin >> b;
res = a + b;
cout << "Summ = " << res << endl;
break;
case 2:
cout << "Enter first number" << endl;
cin >> a;
cout << "Enter second number" << endl;
cin >> b;
res = a - b;
cout << "Sub = " << res << endl;
break;
case 3:
cout << "Enter first number" << endl;
cin >> a;
cout << "Enter second number" << endl;
cin >> b;
res = a * b;
cout << "Mult = " << res << endl;
break;
case 4:
cout << "Enter first number" << endl;
cin >> a;
cout << "Enter second number" << endl;
cin >> b;
if (b != 0)
{
res = a / b;
cout << "Div = " << res << endl;
}
else
cout << "ERROR!!! Division by zero" << endl;
break;
default:
cout << "Enter correct answer" << endl;
break;
}
system("pause");

Комментариев нет:

Отправить комментарий