Question

usingc++1. Write a program to find the Sum(), Subtraction(), Multiplication(), Division() operations using Switch statement. For Divi

0 0
Add a comment Improve this question Transcribed image text
Answer #1
#include <iostream>

using namespace std;

double Sum(double n1, double n2) {
    return n1 + n2;
}

double Subtraction(double n1, double n2) {
    return n1 - n2;
}

double Multiplication(double n1, double n2) {
    return n1 * n2;
}

double Division(double n1, double n2) {
    return n1 / n2;
}

int main() {
    double n1, n2;
    char op;
    cout << "Enter first number: ";
    cin >> n1;
    cout << "Enter operator: ";
    cin >> op;
    cout << "Enter second number: ";
    cin >> n2;

    switch(op) {
        case '+':
            cout << n1 << " = " << n2 << " = " << Sum(n1, n2) << endl;
            break;
        case '-':
            cout << n1 << " = " << n2 << " = " << Subtraction(n1, n2) << endl;
            break;
        case '*':
            cout << n1 << " = " << n2 << " = " << Multiplication(n1, n2) << endl;
            break;
        case '/':
            if (n2 == 0) {
                cout << "Denominator can't be zero" << endl;
            }
            cout << n1 << " = " << n2 << " = " << Division(n1, n2) << endl;
            break;
        default:
            cout << "Invalid operator" << endl;
            break;
    }
    return 0;
}
Add a comment
Know the answer?
Add Answer to:
usingc++ 1. Write a program to find the Sum(), Subtraction(), Multiplication(), Division() operations using Switch statement....
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
Active Questions
ADVERTISEMENT