Trying to make an advanced calculator for a class project.
instructions are:
o Instead of using the variables: num1 and num2 create an array variable named NumberInputs of size 2 to save input in from the keyboard...
o Change the if-else statement in to a switch statement
o Presents errors cleanly, followed by providing instructions for the user
o After the calculation is complete, the program presents the menu again for a new calculation
o Ensure that the calculator can handle large numbers
o Make function that are called for each calculation. For example:
<data_type> Addition(<data_type> <variable>, <data_type> <variable>)
<data_type> Subtraction (<data_type> <variable>, <data_type> <variable>)
<data_type> Multiplication (<data_type> <variable>, <data_type> <variable>)
<data_type> Division (<data_type> <variable>, <data_type> <variable>)
<data_type> Modulus (<data_type> <variable>, <data_type> <variable>)
<data_type>Exponents (<data_type> <variable>, <data_type> <variable>)
• ***Note: <data_type> <variable> should be updated for each function with the correct parameter information. As well as the <data_type> at the begin of the function
o Save the output to the screen and to a file call “calculationOutput.out”
o Add a menu for the user to pick his/her calculation
To do Addition Press ‘A1’ :
To do Subtraction Press ‘S2’
To do Multiplication Press ‘M3’
To do Division Press ‘D4’
To do Modulus Press ‘M5’
To do Exponents Press ‘E6’
To Exit Press ‘E7’
Please choose a calculation: A1
Please enter the first number: 1.23
Pease enter the second number: 1.23
The answer is : 1.23 + 1.23 = 2.46
To do Addition Press ‘A1’ :
To do Subtraction Press ‘S2’
To do Multiplication Press ‘M3’
To do Division Press ‘D4’
To do Modulus Press ‘M5’
To do Exponents Press ‘E6’
To Exit Press ‘E7’
Please choose a calculation: E7
Good Bye
This is where I have my code so far...
Need some help please.
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
|
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
double Addition(double x, double y);
double Subtraction(double x, double y);
double Multiplication(double x, double y);
double Divide(double x, double y);
double Modulus(double x, double y);
double Exponents(double x, double y);
int main() {
std::cout << std::fixed << std::setprecision(2);double result, x, y;
char op, A1, S2, M3, D4, M5, E6, E7;
char calculation;
while (true)
1. To do Addition Press A1
2. To do Subtraction Press S2
3. To do Multiplication Press ‘M3’
4. To do Division Press ‘D4’
5. To do Modulus Press ‘M5’
6. To do Exponents Press ‘E6’
7. To Exit Press ‘E7’
cout << "Please choose a calculation: " <<endl;
cin >> calculation;
cout << "Please enter the first number: " <<endl;
cin >> x;
cout << "Pease enter the second number: " <<endl;
cin >> y;
switch (calculation)
{
case '+': A1 = Addition;
case '-': S2 = Subtraction;
case '*': M3 = Multiplication;
case '/': D4 = Divide;
case '^': M5 = Modulus;
case '%': E6 = Exponents;
default : E7;
break;
}
cout << "The answer is : " << x << calculation << y << " = " << result << endl;
system ("pause");
return 0;
}
double Addition(double x, double y)
{
return x+y;
}
double Subtraction(double x, double y)
{
return x-y;
}
double Multiplication(double x, double y)
{
return x*y;
}
double Divide(double x, double y)
{
return x/y;
}
double Modulus(double x, double y)
{
return static_cast<int>(x) % static_cast<int>(y);
}
double Exponents(double x, double y)
{
return pow(x, y);
}
|