Hello, Im having trouble with this program that is a calculator that does average, range MtoTheNth power and and factorials, which are initiated by a menu that allows the user to choose with function to call. I believe that my functions are arithmetically correct, but every time I run the program, It automatically calls the "range" function through that menu. Here is my code:
/******************************************************************************
CSCI 240 - Program 6 - Summer 2011
do
{
if (number < lowBound || number > upBound)
{
cout << "\nError: " << number << " is invalid. Try again: ";
}
}
while (number < lowBound || number > upBound);
return number;
}
void doAverage()
{
string state1 = "Enter a sum to be averaged between ";
string state2 = "Enter the number of entries ";
int getValue(string prompt, int lowBound, int upBound)
{
int number; //error: number IS NULL ; Can not compare it. Initial value, and then accept the user data. true: int number = 0;
cout << prompt << lowBound << " and " << upBound << ": ";
do
{
////////////////////true: cin>> number;
if (number < lowBound || number > upBound)
{
cout << "\nError: " << number << " is invalid. Try again: ";
}
}
while (number < lowBound || number > upBound);
return number;
}
void doAverage()
{
string state1 = "Enter a sum to be averaged between ";
string state2 = "Enter the number of entries ";
int lowBoundA = 1,
upBoundA = 1000,
lowBoundB = 1,
upBoundB = 1000,
sum,
count;
double average;
sum = getValue(state1, lowBoundA, upBoundA);
count = getValue(state2, lowBoundB, upBoundB);
average = calcAverage(sum, count);
cout << "\nThe average is: "; \\ error: add << average;
return;
}
Program so that you can complete the first feature.
1 2 3 4 5 6 7 8 9 10 11 12 13 14
int calcMtoNth( int M, int N )
{
int MtoNth = 1,
count = 1,
Nth; \\ error: IS NULL
while (count <= Nth) \\error: Nth IS NULL; Nth, is it N ?
{
MtoNth *=M;
count ++;
}
true :cin>> number;