/**********************************************
** NAME
** TEACHER, SECTION
** DATE
** HOMEWORK #6: SNARKY CALCULATOR
** This program will calculate various math
** approximations, or it might just be rude
**********************************************/
#include "userInteraction.h" // a file for input and output with the user
#include "calculator.h" // a file for doing math calculations
int main()
{
srand(time(NULL)); // seed the random numbers
const double CHANCE_OF_SNARK = 0.35; // the chance of snarkiness
const long MIN_SNARK = 3; // the min value the calculator can replace with
const long MAX_SNARK = 9; // the max value the calculator can replace with
const long MIN_SINE_TERMS = 1; // the min allowed number of sine terms
const long MIN_FACTORIAL = 0; // the min allowed factorial input
const long MAX_FACTORIAL = 10; // the max allowed factorial input
const long MIN_ROOT = 1; // the min root the user can find
long menu_option; // the menu option selected
do // until they choose quit
{
menu_option = PresentMenu(); // show and get the menu option
switch (menu_option) // depending on which choice they made
{
case MENU_COSH:
{
long input; // the number to take the hyperbolic cosine of
double cosh; // the hyperbolic cosine of the input
const string REQUEST = "Input a value for x: ";
RequestInput(REQUEST, input); // get a number from the user
if (GetRandomChance(CHANCE_OF_SNARK)) // check for snark
{
input = ChooseRandomNumber(MIN_SNARK, MAX_SNARK); // reject number and
// choose another
cout << "I don't like that input. I like " << input
<< " better." << endl;
}
cosh = Cosh(input); // approximate the hyperbolic cosine of the result
OutputAnswer(MENU_COSH, input, cosh); // output the answer
break;
}
case MENU_FACT:
{
long input; // the number to get the factorial of
long fact; // the factorial of the input
const string REQUEST = "Input a value between 0 and 10: ";
// get a number in the valid factorial range
RequestInput(REQUEST, input, MIN_FACTORIAL, MAX_FACTORIAL);
if (GetRandomChance(CHANCE_OF_SNARK)) // check for snark
{
input = ChooseRandomNumber(MIN_SNARK, MAX_SNARK); // reject number and
// choose another
cout << "I don't like that input. I like " << input
<< " better." << endl;
}
fact = Factorial(input); // calculate the factorial of the input
OutputAnswer(MENU_FACT, input, fact); // output the answer
break;
}
case MENU_EXP:
{
double input; // the number to raise e to
double exp; // the approximation of e raised to input
const string REQUEST = "Input a power to raise e to: ";
RequestInput(REQUEST, input); // get the number to raise e to
if (GetRandomChance(CHANCE_OF_SNARK)) // check for snark
{
input = ChooseRandomNumber(MIN_SNARK, MAX_SNARK); // reject number and
// choose another
cout << "I don't like that input. I like " << input
<< " better." << endl;
}
exp = Exponential(input); // calculate e raise to input
OutputAnswer(MENU_EXP, input, exp); // output the answer
break;
}
case MENU_SIN:
{
double input; // the number to calculate the sine of
long terms; // the number of terms to calculate
double sine; // the result of the sine approximation
string request = "Input a value to take the sine of: ";
RequestInput(request, input); // get the number to calculate sine on
if (GetRandomChance(CHANCE_OF_SNARK)) // check for snark
{
input = ChooseRandomNumber(MIN_SNARK, MAX_SNARK); // reject number and
// choose another
cout << "I don't like that number. I like " << input
<< " better." << endl;
}
request = "Input a positive number of terms to calculate: ";
RequestInput(request, terms, MIN_SINE_TERMS); // get the number of terms
// to calculate
sine = Sine(input, terms); // approximate the sine of the number
OutputAnswer(MENU_SIN, input, sine); // output the answer
break;
}
case MENU_ROOT:
{
double input; // the number we will take the root of
long root; // which root to take
double result; // the result of the root
string request = "Input a value to find the root of: ";
RequestInput(request, input); // get the number to take the root of
request = "Input the root to find (minimum 1): ";
RequestInput(request, root, MIN_ROOT); // get the root to take
result = Root(input, root); // calculate the root
OutputAnswer(MENU_ROOT, input, result); // output the answer
break;
}
case MENU_SNARK: // the calculator has decided to be snarky
{
RandomMenuSnark(); // output a random snark message
break;
}
case MENU_QUIT:
{
break; // do nothing on quit
}
}
} while (menu_option != MENU_QUIT); // until they choose to quit
return 0;
}