This repository has been archived on 2024-10-24. You can view files and clone it, but cannot push or open issues or pull requests.
NG_2024_Stanislav_Mykhailenko/Lesson_1/Task_4/main.cpp

48 lines
1,004 B
C++
Raw Normal View History

2024-06-04 08:40:07 +00:00
#include <iostream>
2024-06-11 07:48:26 +00:00
using namespace std;
2024-06-04 08:40:07 +00:00
int main()
{
float firstNumber = 0;
float secondNumber = 0;
float result = 0;
2024-06-11 07:48:26 +00:00
char operation = 0;
2024-06-04 08:40:07 +00:00
2024-06-11 07:48:26 +00:00
cout << "Enter the first number: ";
cin >> firstNumber;
2024-06-04 08:40:07 +00:00
2024-06-11 07:48:26 +00:00
cout << "Enter the second number: ";
cin >> secondNumber;
2024-06-04 08:40:07 +00:00
2024-06-11 07:48:26 +00:00
cout << "Enter operation: ";
cin >> operation;
2024-06-04 08:40:07 +00:00
switch (operation) {
case '+':
result = firstNumber + secondNumber;
break;
case '-':
result = firstNumber - secondNumber;
break;
case '*':
result = firstNumber * secondNumber;
break;
case '/':
if (secondNumber == 0) {
2024-06-11 07:48:26 +00:00
cout << "Division by zero" << endl;
2024-06-04 08:40:07 +00:00
return 1;
}
result = firstNumber / secondNumber;
break;
default:
2024-06-11 07:48:26 +00:00
cout << "Unknown operation." << endl;
2024-06-04 08:40:07 +00:00
return 2;
break;
}
2024-06-11 07:48:26 +00:00
cout << result << endl;
2024-06-04 08:40:07 +00:00
return 0;
}