Compiler keeps saying "Local definitions are illegal"

Hello!

Forgive something so remedial but I'm completely stuck. It keeps giving me the "Local definitions are illegal" error referencing the findLowest function in the code below. This is for a program for class that will have me getting 5 scores from the user, dropping the lowest, and averaging the rest. If you guys can help me get unstuck so I can finish the rest of the program I would be very grateful. Also does the rest of it make any sense? Is my logic correct? I'll have another function that will find the average of the 4 elements of score that are not equal to "lowest" after the minimum value is found by the program. I am a total noob I know but if anyone could help I'd really appreciate it.


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
#include <iostream>
using namespace std;
 
int main ()
{
       void getScore(int []);
       int findLowest(int, int, int, int, int);
 
       int score[5];
       int lowest;
      
       cout << "This program will ask you to enter 5 test scores. It will then drop the lowest\n";
 
       getScore(score);
       getScore(score);
       getScore(score);
       getScore(score);
       getScore(score);
       lowest = findLowest(score[1], score[2], score[3], score[4], score[5]);
 
       return 0;
}
 
void getScore(int &input)
{
       cout <<"Please enter a test score: ";
       cin >> input;
       if(input < 0 || input > 100)
              { cout << "I'm sorry that's invalid input";
}
 
int findLowest(int one, int two, int three, int four, int five)
{
    int output = one;
    if(output > two){ output = two;}
    if(output > three){ output = three;}
    if(output > four){ output = four;}
    if(output > five){ output = five;}
    return output;
}
Either remove the { on line 29 or add a } to the end of it. You don't currently have a terminating brace for the definition of getScore so the compiler thinks you're trying to define findLowest within the getScore function.

Generally, function declarations are made at global scope (outside of a function.) Line 6 should be void getScore(int&); to match the actual definition.

Also, lines 14 through 18 should be:
1
2
3
    getScore(score[0]);
    getScore(score[1]);
    ...
Last edited on
oh my goodness. I can't believe I didn't see that. I'm really sorry for wasting your time with the function bracket :(

As far as the rest, thanks! The array and reference concepts I just learned so I appreciate the help on those!
Last edited on
An improvement would be to put the gathering of the input into a for loop - what if you had do this for 100 items?

Also, reorganise the findLowest function so it takes the array as an argument rather all it's items individually - again what if there 100 items?

To avoid mismatched braces when using an ordinary text editor (not one that is part of an IDE), get into the habit of typing the closing brace (or any other thing that comes in pairs) immediately after the opening one, as in :

if(){}

Then go back and fill in the rest. When doing a class or struct or anything else that requires a semicolon after the closing brace, do this first also.

I did this for about 20 years, then started using an IDE that automatically did closing braces etc. So then I had to unlearn my somewhat pedantic behaviour .....
Thank you I really appreciate the advice :)
edit: I'm not retarded I'm special. I should really pay attention to the spelling of my function names.
Last edited on
Topic archived. No new replies allowed.