/
spirzen
/
it-code-examples
Обзор
Документация
Войти
/
spirzen
/
it-code-examples
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
examples/cpp/cpp-506-1005-003/main.cpp
38 строк
1 KB
Spirzen
Code migration pack
09 июн 2026, 01:41
09 июн 2026, 01:41
cebc284
Код
Авторство
О чём код?
#include <iostream> #include <limits> double calculate(double a, double b, char op) { switch (op) { case '+': return a + b; case '-': return a - b; case '*': return a * b; case '/': if (b == 0) throw std::runtime_error("Деление на ноль"); return a / b; default: throw std::invalid_argument("Неизвестная операция"); } } int main() { double num1, num2; char operation; std::cout << "Введите первое число: "; std::cin >> num1; std::cout << "Введите операцию (+, -, *, /): "; std::cin >> operation; std::cout << "Введите второе число: "; std::cin >> num2; try { double result = calculate(num1, num2, operation); std::cout << "Результат: " << result << std::endl; } catch (const std::exception& e) { std::cerr << "Ошибка: " << e.what() << std::endl; return 1; } return 0; }