The calling statements that are placed in main() should replace the calculations that are currently in the switch statement.
I need to write and use the following functions:
int addition( int value1, int value2 )
int subtraction( int value1, int value2 )
int multiplication( int value1, int value2 )
int quotient( int value1, int value2 )
int remainder( int value1, int value2 )
int power( int value1, int value2 )
int factorial( int value )
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110
|
#include <iostream>
#include <iomanip>
#include <fstream>
#include <cstdlib>
#include <cmath>
using namespace std;
int main()
{
char operation;
int num1, num2, result, remain;
//Display the menu to the user and get their first choice
cout << "What operation would you like to perform:" << endl
<< " + addition\n - subtraction\n * multiplication\n / division\n ^ number to power\n ! factorial"
<< "\n q quit" << endl << endl << "Operation? ";
cin >> operation;
while (operation != 'q')
{
//Switch - the user does not want to quit
switch (operation)
{
case '+':
//read input first
cout << "Enter the first number to add: " << endl;
cin >> num1;
cout << "Enter the second number to add: " << endl;
cin >> num2;
//compute the results
result=num1+num2;
cout << endl << num1 << " + " << num2 << " = " << result;
break;
case '-':
//read input first
cout << "Enter the first number to subtract: " << endl;
cin >> num1;
cout << "Enter the second number to subtract: " << endl;
cin >> num2;
//compute the results
result=num1-num2;
cout << endl << num1 << " - " << num2 << " = " << result;
break;
case '*':
//read input first
cout << "Enter the first number to multiply: " << endl;
cin >> num1;
cout << "Enter the second number to multiply: " << endl;
cin >> num2;
//compute the results
result=num1*num2;
cout << endl << num1 << " * " << num2 << " = " << result;
break;
case '/':
//read input first
cout << "Enter the dividend: " << endl;
cin >> num1;
cout << "Enter the divisor: " << endl;
cin >> num2;
//compute the results
result=num1/num2;
cout << endl << num1 << " / " << num2 << " = " << result;
result=num1%num2;
cout << endl << num1 << " % " << num2 << " = " << result;
break;
case '^':
//read input first
cout << "Enter the base number " << endl;
cin >> num1;
cout << "Enter the power: " << endl;
cin >> num2;
//compute the results
result=num1^num2;
cout << endl << num1 << " ^ " << num2 << " = " << result;
break;
case '!':
//read input first
cout << "Enter a number: " << endl;
cin >> num1;
//compute the results
num1!=result;
cout << endl << num1 << " ! " << " = " << result;
break;
default:
cout << "That is an invalid operation!" << endl;
break;
} // switch statement closed
cout << endl << "What operation would you like to perform:" << endl
<< " + addition\n - subtraction\n * multiplication\n / division\n ^ number to power\n ! factorial"
<< "\n q quit"
<< endl << endl << "Operation? ";
cin >> operation;
}
return 0;
} //main statement closed
|