// Sean Szumlanski
// 7/15/02
// This program gives the user the option to calculate several standard
// mathematical functions. After the user chooses an option and enters
// the operands for the function, the answer is displayed and the menu
// is reprompted so that the user can carry out extra calculations until
// they choose to quit.
#include <iostream.h>

int main() {

	double  num1, num2, answer;
	int     option, exit = 0;


	cout << "Welcome to my Calculator Program!\n\n";

        // Continue until the user wants to quit.
	while (!exit) {

		// Display the menu options
		cout << "1. Add Two Numbers" << endl;
		cout << "2. Subtract Two Numbers" << endl;
		cout << "3. Multiply Two Numbers" << endl;
		cout << "4. Divide Two Numbers" << endl;
		cout << "5. Raise a Number to a Power" << endl;
		cout << "6. Exit Program" << endl;

		cout << "\nSelect an option: ";

		cin >> option;

 		// Execute the appropriate menu choice.
		if (option == 1) {

			// Prompt & read in the operands & output the result. 
			cout << "\nEnter the two numbers to be added, separated by a space: ";
			cin >> num1 >> num2;
			cout << "\n" << num1 << " + " << num2 << " = " << (num1 + num2) << "\n\n";
		}

		else if (option == 2) {
			cout << "\nEnter the two numbers to be subtracted, separated by a space: ";
			cin >> num1 >> num2;
			cout << "\n" << num1 << " - " << num2 << " = " << (num1 - num2) << "\n\n";
		}

		else if (option == 3) {
			cout << "\nEnter the two numbers to be multiplied, separated by a space: ";
			cin >> num1 >> num2;
			cout << "\n" << num1 << " * " << num2 << " = " << (num1 * num2) << "\n\n";
		}

		else if (option == 4) {
			cout << "\nEnter the quotient, followed by the divisor, separated by a space: ";
			cin >> num1 >> num2;
			cout << "\n" << num1 << " / " << num2 << " = " << (num1 / num2) << "\n\n";
		}

		else if (option == 5) {
			answer = 1;

			cout << "\nEnter the number to be raised to some power: ";
			cin >> num1;
			cout << "Enter the power to which you want to raise " << num1 << ": ";
			cin >> num2;

			// Calculate the power function with repeated mult.
			for (int i=0; i < (int)num2; i++) {
				answer *= num1;
			}

			cout << "\n" << num1 << " ^ " << num2 << " = " << answer << "\n\n";
		}

		else if (option == 6) {
			cout << "\nGoodbye!\n";
			exit = 1;
		}

		else
			cout << "\nThat is not a valid option. Please try again.\n\n";

	}

	return 0;
}
