Answer to Question #128363 in C++ for Zeeshan ali

Question #128363
Design a calculator using the concept of functions. Take user defined values for each operation.
1
Expert's answer
2020-08-05T16:44:13-0400
#include <iostream>
using namespace std;

void sum(int a, int b) {
    cout << "sum is: " << a + b;
}

void dif(int a, int b) {
    cout << "different is: " << a - b;
}

void mult(int a, int b) {
    cout << "multiplication is: " << a * b;
}

void division(int a, int b) {
    if (b == 0) {
        cout << "ERROR!";

    } else {
        cout << "division is: " << a / b;
    }
}


int main() {

    int a, b;
    char op;
    cout << "Enter a\n";
    cin >> a;
    cout << "Enter b\n";
    cin >> b;
    cout << "Choose operation: + = * /\n";
    cin >> op;
    switch (op) {
        case '+':
            sum(a, b);
            break;
        case '-':
            dif(a, b);
            break;
        case '/':
            division(a, b);
            break;
        case '*':
            mult(a, b);
            break;
        default:
            cout << "unknown operation!";
    }

}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS