This code works as it is supposed to:
#include<iostream>
#include<cmath>
#include<cstdlib>
using namespace std;
int main()
{
char cAgain, type;
int x, y=0;
double addition(double num1, double num2), subtraction(double num1, double num2), division(double num1, double num2),
multiplication(double num1, double num2), exponential(double num1, double num2), num1, num2, total;
do
{
cout << "How many operations would you like to do?" << endl;
cin >> x;
if (x <= 0)
{
cout << "Error: You must have 1 or more operations." << endl;
}
else
{
while (x != 0, x--)
{
y++;
cout << "Enter in your "<<y<< " operation. (First Number (+,-,*,/,^) Second Number)" << endl;
cin >> num1 >> type >> num2;
switch (type)
{
case '+':
total = addition(num1, num2);
cout << num1 << " + " << num2 << "= " << total<< endl;
break;
case'-':
total = subtraction(num1, num2);
cout << num1 << " - " << num2 << "= " << total<< endl;
break;
case'/':
total = division(num1, num2);
cout << num1 << " / " << num2 << "= " << total<< endl;
break;
case'*':
total = multiplication(num1, num2);
cout << num1 << " * " << num2 << "= " << total << endl;
break;
case'^':
total = exponential(num1, num2);
cout << num1 << " ^ " << num2 << "= " << total << endl;
break;
}
}
}
cout << "Would you like to run the program again.(Y/N)" << endl;
cin >> cAgain;
} while (cAgain == 'Y' || cAgain == 'y');
return 0;
}
double addition(double num1, double num2)
{
double total;
total = num1 + num2;
return (total);
}
double subtraction(double num1, double num2)
{
double total;
total = num1 - num2;
return (total);
}
double division(double num1, double num2)
{
double total;
total = num1 / num2;
return (total);
}
double multiplication(double num1, double num2)
{
double total;
total = num1 * num2;
return (total);
}
double exponential(double num1, double num2)
{
double total;
total = pow(num1,num2);
return (total);
}
It starts by asking for the number of operations to perform. You enter a number, such as 3. Then it asks you to enter in your operation, such as 5+5, which is 10. Then it asks for a second, such as 10^2, which is 100. Then it asks for a third, such as 100-10, which is 90. Then it asks if you'd like to start over.
Command Pattern
. Then use astd::map<char, Command>
\$\endgroup\$