#include <iostream>
#include <iomanip>
usingnamespace std;
int Sum;
int Count;
int number;
int M;
int N;
int number1;
int number2;
int number3;
int number4;
/* Function Prototypes*/
string Menu();
int getValue("Enter a Number",0,10000);
void doAverage();
double calcAverage(int Sum,int Count);
void doFactorial();
int calcFactorial(int number);
void doMtoNth();
int calcMtoNth(int M,int N);
void doRange();
int calcRange(int number1,int number2,int number3,int number4);
int main()
{
string userChoice;
userChoice = Menu();
while ( userChoice != "Q" && userChoice != "q")
{
if (userChoice == "1")
{
cout << "Enter sum:" << endl;
cin >> Sum;
cout << "Enter total count:" << endl;
cin >> Count;
doAverage();
cout << "The average of " << Sum << " and " << Count << "is " << Average << endl;
}
elseif (userChoice == "2")
{
cout << "Enter a number between 0 and 10:" << endl;
cin >> number;
doFactorial();
cout << "The factorial of " << number << " is " << Factorial << endl;
}
elseif (userChoice == "3")
{
cout << "Enter the M value between 1 and 10:"<< endl;
cin >> M;
cout << "Enter the N value between 1 and 8:" << endl:
cin >> N;
doMtoNth();
cout << M << "Raised to the" << N << "th Power is " << Mth << endl;
}
elseif (userChoice == "4")
{
cout << "Enter a number between 0 and 10000: " << endl;
cin >> number1;
cout << "Enter another number between 0 and 10000: " << endl:
cin << number2;
cout << "Enter another number between 0 and 10000: " << endl:
cin >> number3;
cout << "Enter another number between 0 and 10000: " << endl:
cin >> number4;
doRange();
cout << "The range of " << number1 << ", " << number2 << ", " << number3 << "and " << number4 << " is " << Range << endl;
}
userChoice = Menu();
system ("pause");
return 0;
}
An example output is listed below. It is supose to loop until Q or q is entered. I am not getting this at all.
Special Purpose Calculator
1) Average
2) Factorial
3) M to the Nth Power
4) Range
Q) Quit
Enter your choice: 2
Enter a number between 0 and 10: 8
The facotrial of 8 is 40320
Special Purpose Calculator
1) Average
2) Factorial
3) M to the Nth Power
4) Range
Q) Quit
Enter your choice: 3
Enter the M value between 1 and 10: -5
Error: -5 is invalid. Try again: 17
Error: 17 is invalid. Try again: 9
Enter the N value between 1 and 8: 3
9 raised to the 3th power is 729
Special Purpose Calculator
1) Average
2) Factorial
3) M to the Nth Power
4) Range
Q) Quit
Enter your choice: 567
Error: 567 is invalid. Try again: 78
Error: 78 is invalid. Try again: 6
Error: 6 is invalid. Try again: -1
Error: -1 is invalid. Try again: 4
Enter a number between 0 and 10000: 100
Enter another number between 0 and 10000: 53
Enter another number between 0 and 10000: 222
Enter another number between 0 and 10000: 718
The range of 100, 53, 222 and 718 is 665
Special Purpose Calculator
1) Average
2) Factorial
3) M to the Nth Power
4) Range
Q) Quit
Enter your choice: Q
I know some of the variables are not declared like Range, Average, Factorial, etc.. but if anyone sees anything wrong please let me know! thanks in advance!!
Any invocations to a function without a definition will result in undefined references. These are errors which indicate that the linker cannot locate the definition of the function you're trying to invoke.
In the condition of the while, instead of logical AND, use logical OR.