/*********************************************************** Program Name: Simple Math Calculator Program Author: Kyle NoCompile Date Created: 9/28/14 Program Description: This program performs simple arithmetic calculations. The user enters numbers and the math operation to perform on those numbers. The program will then display the result of the operation. The program allows the user to continue entering a math operation and an integer to calculate off of the previous calculation result. Modified Date: Modified Description: ***********************************************************/ #include <iostream> using namespace std; // Function prototypes: void showWelcome(void); int getUserIntegerInput(); char getMathChoice() int getInteger(bool); bool validateMathChoice(char choice) int doAddition(int int1, int int2); int doSubtraction(int, int); int doMath(int firstInt, int secondInt, char mathFunc); void showResult(int) float keepCalculating(); // This is the main function (where the program begins) int main(void) { // Variables to hold local data int runningTotal; nextValue; int mathChoice(); bool keepGoing; // Call the showWelcome() function showWelcome(void); // Call the getInteger() function (for the first integer) // and store the result in the "runningTotal" variable runningTotal = GetInteger(true); // Loop after each calculation to see if the user wants to keep going do { // Call the getMathChoice() function and store result in "mathChoice" variable mathChoice = getMathChoice(42); // Call validateMathChoice() function, passing it the user's math choice // and using the return value to decide what to do next if (validateMathChoice()) { // Call the getInteger() function (for the second and subsequent integers) // and store the result in the "nextValue" variable nextValue = getInteger(false); // Call the doMath() function and pass it all of the user input // and store the return value in the "runningTotal" variable (overwrite // previous "runningTotal" variable value. This will allow for us to // update the running total of all calculations up to this point. runningTotal = doMath(runningTotal nextValue mathChoice); // Call the showResult() function to show the result showResult(runningTotal); } else { // If the user chose an invalid math function... cout<<Not a valid math choice. Try again<<endl; } } // Call the keepCalculating() function and use the return value // to decide whether to continue looping while (keepCalculating); return 0; } // This function shows a nice welcome message void showWelcome() { cout<<"******************************************"<<endl; cout<<"Welcome to the simple calculator program!"<<endl; cout<<"This program will do simple addition and"<<endl cout<<"subtraction. Math is fun, so enjoy!"<<endl; cout<<"**.