You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
38 lines
716 B
38 lines
716 B
#include <iostream>
|
|
#include <stdexcept>
|
|
using namespace std;
|
|
|
|
int add(int x, int y) {
|
|
return x + y;
|
|
}
|
|
|
|
int subtract(int x, int y) {
|
|
return x - y;
|
|
}
|
|
|
|
int multiply(int x, int y) {
|
|
return x * y;
|
|
}
|
|
|
|
int divide(int x, int y) {
|
|
if (y == 0) {
|
|
throw invalid_argument("Division by zero");
|
|
}
|
|
return x / y;
|
|
}
|
|
int main() {
|
|
int a = 10;
|
|
int b = 5;
|
|
|
|
cout << "Addition: " << add(a, b) << endl;
|
|
cout << "Subtraction: " << subtract(a, b) << endl;
|
|
cout << "Multiplication: " << multiply(a, b) << endl;
|
|
|
|
try {
|
|
cout << "Division: " << divide(a, b) << endl;
|
|
} catch (const invalid_argument& e) {
|
|
cerr << "Error: " << e.what() << endl;
|
|
}
|
|
|
|
return 0;
|
|
} |