Answer to Question #328514 in C++ for florence

Question #328514

write a program to perform the following task

a. prompt a user to enter three number of any data type (int or float)

b. create a function which accept three numbers

c. prompt a user to select the mathematic operation ( +, -, %, *, etc)

Display the result of the mathematic operation of the three numbers.

entered according to the user choice

sample output

Enter the Number

!st Number :37.5

2st Number :10;3rd Number ;20


please select operation

A: +, B|:-, C: *, D:% etc


operation: A

the summation of 37.5, 10, and 20 is 67.

5


1
Expert's answer
2022-04-14T06:16:10-0400
#include <iostream>
using namespace std;


void do_arithmetics(double x, double y, double z) {
    char ch;
    double result;


    cout << endl;
    cout << "Please select operation" << endl;
    cout << "A: +  B: -  C: *  D: /" << endl;
    cin >> ch;


    switch (ch) {
        case 'A':
            result = x + y + z;
            cout << "The summation of " << x << ", " << y << ", and "
                 << z << " is " << result << endl;
            break;
        case 'B':
            result = x - y - z;
            cout << "The subtraction of " << y << " and " << z 
                 << " from " << x << " is " << result << endl;
            break;
        case 'C':
            result = x * y * z;
            cout << "The multiplication of " << x << ", " << y << ", and "
                 << z << " is " << result << endl;
            break;
        case 'D':
            result = x / y / z;
            cout << "The devision of " << x << " by " << y << " and "
                 << z << " is " << result << endl;
            break;
        default:
            cout << "Incorrect operatipn" << endl;
    }
}


int main() {
    double x, y, z;


    cout << "Enter the numbers" << endl;
    cout << "1st number: ";
    cin >> x;
    cout << "2nd number: ";
    cin >> y;
    cout << "3rd number: ";
    cin >> z;


    do_arithmetics(x, y, z);


    return 0;
}

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