- #include "stdio.h"
- int main()
- {
- char operator;
- double operand1, operand2, result;
- char continueCalculation = 'y';
- while (continueCalculation == 'y')
- {
- scanf("%lf %c %lf", &operand1, &operator, &operand2);
- switch (operator)
- {
- case '+':
- result = operand1 + operand2; break;
- case '-':
- result = operand1 - operand2; break;
- case '*':
- result = operand1 * operand2; break;
- case '/':
- if (operand2 != 0)
- {
- result = operand1 / operand2;
- }
- else
- {
- printf("Error (Division by zero)\n");
- continue;
- }
- break;
- default:
- printf("Error (Invalid operator)\n");
- continue;
- }
- printf("%.2lf %c %.2lf = %.2lf\n", operand1, operator, operand2, result);
- scanf(" %c", &continueCalculation);
- }
- return 0;
- }