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
#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;
}
Comments
Leave a comment