Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- void addition(int a, int b) {
- cout << a + b << endl;
- }
- void subtraction(int a, int b) {
- cout << a - b << endl;
- }
- void multiplication(int a, int b) {
- cout << a * b << endl;
- }
- void division(int a, int b) {
- if (b != 0) {
- cout << (double)a / b << endl;
- }
- else {
- cout << "Can't divide by zero." << endl;
- }
- }
- int main() {
- double n1, n2;
- cin >> n1 >> n2;
- char operation;
- cin >> operation;
- if (operation == '+') {
- addition(n1, n2);
- }
- else if (operation == '-') {
- subtraction(n1, n2);
- }
- else if(operation == '*') {
- multiplication(n1, n2);
- }
- else {
- division(n1, n2);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement