1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113
|
#include"calculator_funcs.h"
#include<iostream>
using namespace std;
// 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<<"******************************************"<<endl;
}
// This function gets integer input from the user
int getUserIntegerInput()
{
int input;
cin >> input;
return input;
}
// This function asks the user for a math function
// and returns the user's input
char getMathChoice()
{
char choice;
cout <<"Please select a math function to perform (\"+\" = Addition, \"-\" = Subtraction): "<< endl;
cin>> choice;
return choice;
}
// this function asks the user for either the first integer
// or the second and returns the user's input
int getInteger(bool firstNumber)
{
cout <<"Please enter the "<<endl;
// if the "firstNumber" variable is true, then this
// is the first number being collected
if (firstNumber)
{
cout <<"first " <<endl;
}
// Otherwise, it's the second number being collected
else
{
cout <<"second "<< endl;
}
cout <<"integer: " << endl;
// Call the getUserIntegerInput() function and return the return value from it
return getUserIntegerInput();
}
// This function validates the user's match function choice
// by returning a true for valid, and a false for invalid
bool validateMathChoice(char choice)
{
if (choice == '+' && choice == '-')
{
return true;
}
else
{
return false;
}
}
// This function adds two integers
int doAddition(int int1, int int2)
{
return int1 + int2;
}
// This function subtracts the second integer
// parameter from the first integer parameter
int doSubtraction(int int1, int int2)
{
return int1 - int2;
}
// This function determines the result of the math
// operation requested by the user
int doMath(int firstInt, int secondInt, char mathFunc)
{
// Initialize result to zero (0)
int result = 0;
// If the math function is a "+", then call the
// doAddition() function and store the return
// value in the "result" variable
if (mathFunc = '+')
{
result = DoAddition( firstInt,secondInt);
}
// If the math function is a "-", then call the
// doSubtraction() function and store the return
// value in the "result" variable
else if (mathFunc == '-')
{
result = DoSubtraction(firstInt,secondInt);
}
return result;
}
// This function displays the result of a math operation
void showResult(int result)
{
cout <<"The result is "<< result << endl;
}
|