#include "userInteraction.h"
long PresentMenu()
{
const double CHANCE_OF_SNARK = 0.25; // percent we might be snarky
bool snarkify; // if we will be snarky
bool valid_input; // if the input is within range
long input; // the user input
do // do at least once
{
OutputMenu(); // print the menu to the console
cin >> input; // read input from the cosole
valid_input = CheckRange(input, MENU_MIN, MENU_MAX); // check if the input
// is in range
if (!valid_input) // if the input is not valid
cout << "You don't do instructions well, do ya? Try again." << endl;
} while (!valid_input); // while input is not valid
snarkify = GetRandomChance(CHANCE_OF_SNARK); // now that we have valid input
// we check to see if we will
// be snarky
if (snarkify) // if we are being snarky
input = MENU_SNARK; // change our menu item to snark instead
return input; // return menu selection
}
void OutputMenu()
{
cout << endl << endl << "---- Options ----" << endl;
for (long i = MENU_MIN; i <= MENU_MAX; i++) // for as many menu options exist
{
switch (i)
{
case MENU_FACT:
{
cout << MENU_FACT << ": Factorial of x" << endl;
break;
}
case MENU_EXP:
{
cout << MENU_EXP << ": Exponential of x" << endl;
break;
}
case MENU_SIN:
{
cout << MENU_SIN << ": Sine of x" << endl;
break;
}
case MENU_ROOT:
{
cout << MENU_ROOT << ": Roots of x" << endl;
break;
}
case MENU_COSH:
{
cout << MENU_COSH << ": Hyperbolic cosine of x" << endl;
break;
}
case MENU_QUIT:
{
cout << MENU_QUIT << ": Quit (and run away)" << endl;
break;
}
default:
{
cout << i << ": Unrecognized menu item" << endl;
break;
}
}
}
cout << endl;
return;
}
void RandomMenuSnark()
{
// the available snark options
const long NUM_SNARK = 9;
const string snark[NUM_SNARK] = {
"No. I'm not going to do that for you.",
"That's not something you need to know.",
"Can't you do that on your own? Why bother me with your problems?",
"Perhaps you need to see a psychologist for this problem.",
"What do you think I am? Your patsy?",
"I don't feel like doing that. Come back later and ask me.",
"Go away!!",
"It's NOT my problem.",
"Ask Milhouse....surely he knows the answer to your stupid question."
};
long index = rand() % NUM_SNARK; // generate a random number in the range
// of snark options
cout << snark[index] << endl; // output the appropriate snark
return;
}