so i talked to the professor and she helped me a bit. im pretty sure i have all the code i need written out, but i have mondo errors
[/code]
My Code:
Code:
using namespace std;
#include<iostream>
#include<iomanip>
double add (double num1, double num2);
//add num1 to num2.
double multiply (double num1, double num2);
//multiply num1 and num2.
double subtract (double num1, double num2);
//subtract num2 from num1.
double divide (double num1, double num2);
//Divide num1 by num2.
void display_stuff (double num1, double num2, double tot, char op);
//Show equation.
int main()
{
int x;
double total, n1, n2;
char letter;
cout << "How many times would you like to run the program?" << endl;
cin >> x;
for (int i=1; i<=x; i++)
{
cout << "Enter a letter A, S, M, or D:" <<endl;
cin >> letter;
switch (letter)
{
case 'A' : cout << "Enter two real numbers to add:" << endl;
cin >> n1 >> n2;
display_stuff (n1, n2, total, '+');
total = add (n1, n2);
break;
case 'S' : cout << "Enter two real numbers to subtract:" << endl;
cin >> n1 >> n2;
display_stuff (n1, n2, total, '-');
total = subtract (n1, n2);
break;
case 'M' : cout << "Enter two real numbers to multiply:" << endl;
cin >> n1 >> n2;
display_stuff (n1, n2, total, '*');
total = multiply (n1, n2);
break;
case 'D' : cout << "Enter two real numbers to divide:" << endl;
cin >> n1 >> n2;
if (n2=0)
cout << "Division by zero is not allowed." << endl;
else
{
display_stuff (n1, n2, total, '/');
total = divide (n1, n2);
}
break;
default: cout << "Must enter an A, M, S, or D!" << endl;
break;
} //End Switch
}
return 0;
}
double add (double num1, double num2)
{
double sum;
sum = num1 + num2;
return sum;
}
double multiply (double num1, double num2)
{
double sum;
sum = num1 * num2;
return sum;
}
double subtract (double num1, double num2)
{
double sum;
sum = num1 - num2;
return sum;
}
double divide (double num1, double num2)
{
double sum;
sum = num1 / num2;
return sum;
}
void display_stuff (double num1, double num2, double tot, char op)
{
cout << setiosflags (ios::fixed | ios::showpoint) << setprecision(2);
cout << num1 << " " << op << " " << num2 << " = " << tot << endl;
}