I can't understand what kind of a retarded compiler allows you to define a function inside a function. |
If you look a bit more carefully at the code, you'll see the OP is not defining a function inside a function:
1 2 3 4 5 6 7 8 9 10
|
void showChoices();
{
cout << "MENU" << endl;
cout << "A. Get the largest value " << endl;
cout << "B. Get the smallest value " << endl;
cout << "C. Get the sum of the values " << endl;
cout << "D. Get the average " << endl;
cout << "E. Get the number of values entered " << endl;
cout << "F. End this program " << endl;
}
|
The semicolon at the end of the first line of that snippet gives it the syntax of a declaration, not a definition. It's legal - if a bit odd - to
declare a function inside another function (but not to define one), so the code is legal C++.
It was almost certainly
intended to be a function definition, and if the OP had gotten the syntax correct for a definition then it would be illegal, paradoxically :D
To the OP: You've also put a semicolon at the end of every while statement, before you open the block. This will also cause very different behaviour from what you doubtless intended. It means that the compiler will consider
;
to be a single, empty statement, and will therefore consider it to be the entire contents of the loop. When you write:
1 2 3 4 5
|
while (menuChoice != 'E');
{
numberOfIntegers++;
inputfile >> integer;
}
|
it's equivalent to:
1 2 3 4 5 6 7 8 9 10
|
while (menuChoice != 'E')
{
// This bit loops
;
} // End of the loop
{
// This bit does not loop - it executes after the loop has finished.
numberOfIntegers++;
inputfile >> integer;
}
|
Even if you'd gotten the syntax correct:
1 2 3 4 5
|
while (menuChoice != 'E')
{
numberOfIntegers++;
inputfile >> integer;
}
|
your loop would run forever once entered. Nothing in that loop changes the value of
menuChoice, so that if
(menuChoice != 'E')
was true at the start of the loop, it would remain true forever, and the loop would run infinitely.