#include <iostream>
#include <iomanip>
using namespace std;
//function prototypes
int menu();
int getNum( string, int, int );
int calcFactorial( int );
int calcMtoN( int, int );
int calcLCM( int, int );
int calcGCD( int, int );
int main()
{
int menuChoice, val1, val2, result;
//Get the user's choice
menuChoice = menu();
//While the user wants to perform a mathematical operation
while( menuChoice != 5 )
{
// If the user wants to calculate a factorial, then get a number from the user,
// perform the calculation, and display the result
if( menuChoice == 1 )
{
val1 = getNum( "Enter a number", 0, 10 );
result = calcFactorial( val1 );
cout << endl << "The factorial of " << val1 << " is " << result;
}
// Otherwise if the user wants to raise a number to a power, then get the number
// and power from the user, perform the calculation, and display the result
else if( menuChoice == 2 )
{
val1 = getNum( "Enter a number to be raised to a power", 1, 20 );
val2 = getNum( "Enter the power", 1, 6 );
result = calcMtoN( val1, val2 );
cout << endl << val1 << " raised to the " << val2 << " power is " << result;
}
// Otherwise if the user wants to calculate the least common multiple, then get
// the two numbers from the user, perform the calculation, and display the result
else if( menuChoice == 3 )
{
val1 = getNum( "Enter the 1st number", 1, 50 );
val2 = getNum( "Enter the 2nd number", 1, 50 );
result = calcLCM( val1, val2 );
cout << endl << "The least common multiple of " << val1 << " and " << val2 << " is " << result;
}
// Otherwise the user wants to calculate the greatest common divisor, then get
// the two numbers from the user, perform the calculation, and display the result
else
{
val1 = getNum( "Enter the 1st number", 1, 50 );
val2 = getNum( "Enter the 2nd number", 1, 50 );
result = calcGCD( val1, val2 );
cout << endl << "The greatest common divisor of " << val1 << " and " << val2 << " is " << result;
}
//Wait until the user presses Enter before displaying the menu again
system("pause");
//Get the user's next choice
menuChoice = menu();
}
cout << endl << endl << "Thank you for using the Math Operations Program" << endl;
return 0;
}