Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Решение с тернарен оператор:
- #include <iostream>
- using namespace std;
- int main() {
- int firstNumber, secondNumber;
- cin >> firstNumber >> secondNumber;
- char mathOperator;
- cin >> mathOperator;
- string evenOrOdd;
- double result;
- if (mathOperator == '+' || mathOperator == '-' || mathOperator == '*') {
- result =
- mathOperator == '+' ? firstNumber + secondNumber :
- mathOperator == '-' ? firstNumber - secondNumber : firstNumber * secondNumber;
- cout << firstNumber << ' ' << mathOperator << ' ' << secondNumber << " = " << result << " - " << (result % 2 == 0 ? "even" : "odd") << endl;
- }
- else {
- if (secondNumber == 0) {
- cout << "Cannot divide " << firstNumber << " by zero" << endl;
- }
- else {
- if (mathOperator == '/') {
- result = firstNumber * 1.0 / secondNumber;
- cout.setf(ios::fixed);
- cout.precision(2);
- }
- else {
- result = firstNumber % secondNumber;
- }
- cout << firstNumber << ' ' << mathOperator << ' ' << secondNumber << " = " << result << endl;
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement