Local Function Definitions are illegal

Making a program to find the winner of a talent contest. In this contest the highest and lowest score are dropped then divided by 3 (the remaining scores) to find the winner. I have an error stating Error 2601: 'calcAvgScore': local function definitions are illegal, I have another stating IntelliSense expected a ';'. I have noted in comments in my code where these are happening. I am thinking it is a bracket missing for the local function but have no idea where it needs to be. With the ; issue, if I put one where stated it produces a lot more errors.

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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
     // Cassandra Hamric
  // Sinclair's Got Talent
// This program is not finished
//This program will find the winner of a talent contest by dropping contestants highest and lowest score and dividing by the leftover scores (3).
// In the event of a tie, winner will be first performer. 

#include <iostream>
	#include <iomanip>
	#include <string>
	using namespace std;



// Function Prototypes

	double ValidScore (double); // Ensures Scores are not lower than 1 or greater than 10. 
	double findLowest(double, double, double, double, double);
	double findHighest(double, double, double, double, double);
	double calcAvgScore(double, double, double, double, double);

	int main()
	{
	// variables for user input
	bool isValid;
	double score1, score2, score3, score4, score5, score;
	int highest, lowest; 
	double winnerAverage;
	string name, winnerName;
	
//Get Contestants names, when Done is entered loop quits
	
	do 
	{

	cout <<"Enter the name of the star, enter Done when there are no more stars.";
	cin >> name;
	cout << endl;
	
	if (name != "Done")

	{
		cout <<"Enter Judge 1's Score: ";
		cin >> score;
		score1 = ValidScore (score);

		cout <<"Enter Judge 2's Score: ";
		cin >> score;
		score2 = ValidScore (score);

		cout <<"Enter Judge 3's Score: ";
		cin >> score;
		score3 = ValidScore (score);

		cout <<"Enter Judge 4's Score: ";
		cin >> score;
		score4 = ValidScore (score);

		cout <<"Enter Judge 5's Score: ";
		cin >> score;
		score5 = ValidScore (score);
		}

	double average = calcAvgScore (score1, score2,score3,score4,score5);
    if (average > winnerAverage)
           {
            winnerAverage = average;
            winnerName = name;
    }

	} while (name != "Done");

	// Calculating Averages (drops highest and lowest achieved score, then divides by remaining scores (3))

	double calcAvgScore(double score1, double score2, double score3, double score4, double score5)   // HERE IS WHERE A ; IS EXPECTED and LOCAL FUNCTION DEFINITIONS ARE ILLEGAL
	{
		double highest = findHighest(score1, score2, score3, score4, score5);
		double lowest = findLowest(score1, score2, score3, score4, score5);
		double total = (score1 + score2 + score3 + score4 + score5 - highest - lowest);
		double average = (total) / 3;
		return average;
	}
	// Declaring Winner
	cout << " ... and the winner is " <<winnerName <<" with a score of " <<winnerAverage <<endl;

	system ("pause");
		return 0;
	
	}
	
// Validate Score is not less than 1 or greater than 10

	double ValidScore (int score)
	{
			while ( score < 1 || score > 10)
			{
				cout <<" Please enter a score between 1-10: ";
				cin >> score;
			}
			return score;
	}
	
	// define function to find lowest score for each contestant
	double findLowest(double score1, double score2, double score3, double score4, double score5)
	{
		double lowest = score1;
		if (score2 < lowest)
			lowest = score2;
		if (score3 < lowest)
			lowest = score3;
		if (score4 < lowest)
			lowest = score4;
		if (score5 < lowest)
			lowest = score5;

		return lowest;
	}

	// define function to find highest score for each contestant
	double findHighest(double score1, double score2, double score3, double score4, double score5)
	{
		double highest = score1;
		if (score2 > highest)
			highest = score2;
		if (score3 > highest)
			highest = score3;
		if (score4 > highest)
			highest = score4;
		if (score5 > highest)
			highest = score5;

		return highest;
	}
You're creating functions inside other functions. You're not allowed to do that.

calcAvgScore is inside the function main. Move it out of the function main.
When I move that out of the function main, I get this whole next set of errors. I am so ready to be done with this class!!! AHHHHHH

Warning 4 warning C4700: uninitialized local variable 'winnerAverage' Warning 3 warning C4101: 'lowest' : unreferenced local variable
Warning 2 warning C4101: 'isValid' : unreferenced local variable
Warning 1 warning C4101: 'highest' : unreferenced local variable
Error 5 error LNK2019: unresolved external symbol "double __cdecl ValidScore(double)" (?ValidScore@@YANN@Z) referenced in function _main

Error 6 error LNK1120: 1 unresolved externals

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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129


#include <iostream>
	#include <iomanip>
	#include <string>
	using namespace std;



// Function Prototypes

	double ValidScore (double); // Ensures Scores are not lower than 1 or greater than 10. 
	double findLowest(double, double, double, double, double);
	double findHighest(double, double, double, double, double);
	double calcAvgScore(double, double, double, double, double);

	int main()
	{
	// variables for user input
	bool isValid;
	double score1, score2, score3, score4, score5, score;
	int highest, lowest; 
	double winnerAverage;
	string name, winnerName;
	
//Get Contestants names, when Done is entered loop quits
	
	do 
	{

	cout <<"Enter the name of the star, enter Done when there are no more stars.";
	cin >> name;
	cout << endl;
	
	if (name != "Done")

	{
		cout <<"Enter Judge 1's Score: ";
		cin >> score;
		score1 = ValidScore (score);

		cout <<"Enter Judge 2's Score: ";
		cin >> score;
		score2 = ValidScore (score);

		cout <<"Enter Judge 3's Score: ";
		cin >> score;
		score3 = ValidScore (score);

		cout <<"Enter Judge 4's Score: ";
		cin >> score;
		score4 = ValidScore (score);

		cout <<"Enter Judge 5's Score: ";
		cin >> score;
		score5 = ValidScore (score);
		}

	double average = calcAvgScore (score1, score2,score3,score4,score5);
    if (average > winnerAverage)
           {
            winnerAverage = average;
            winnerName = name;
    }

	} while (name != "Done");

	// Declaring Winner
	cout << " ... and the winner is " <<winnerName <<" with a score of " <<winnerAverage <<endl;

	system ("pause");
		return 0;
	
	}

	// Calculating Averages (drops highest and lowest achieved score, then divides by remaining scores (3))

	double calcAvgScore(double score1, double score2, double score3, double score4, double score5)   // HERE IS WHERE A ; IS EXPECTED and LOCAL FUNCTION DEFINITIONS ARE ILLEGAL
	{
		double highest = findHighest(score1, score2, score3, score4, score5);
		double lowest = findLowest(score1, score2, score3, score4, score5);
		double total = (score1 + score2 + score3 + score4 + score5 - highest - lowest);
		double average = (total) / 3;
		return average;
	}
	
// Validate Score is not less than 1 or greater than 10

	double ValidScore (int score)
	{
			while ( score < 1 || score > 10)
			{
				cout <<" Please enter a score between 1-10: ";
				cin >> score;
			}
			return score;
	}
	
	// define function to find lowest score for each contestant
	double findLowest(double score1, double score2, double score3, double score4, double score5)
	{
		double lowest = score1;
		if (score2 < lowest)
			lowest = score2;
		if (score3 < lowest)
			lowest = score3;
		if (score4 < lowest)
			lowest = score4;
		if (score5 < lowest)
			lowest = score5;

		return lowest;
	}

	// define function to find highest score for each contestant
	double findHighest(double score1, double score2, double score3, double score4, double score5)
	{
		double highest = score1;
		if (score2 > highest)
			highest = score2;
		if (score3 > highest)
			highest = score3;
		if (score4 > highest)
			highest = score4;
		if (score5 > highest)
			highest = score5;

		return highest;
	}
They are not new errors. Your code had them all along. The compilation just did not reach them due to the local function definition error.

A warning is not an error that prevents compilation, but it alerts you about suspicious code.

This program should give similar warnings:
1
2
3
4
5
6
7
8
9
10
#include <iostream>

int main() {
  double foo; // unused variable
  int bar;
  if ( bar < 42 ) { // using uninitialized variable
    std::cout << "Hello";
  }
  return 0;
}


The linker error is same as in this:
1
2
3
4
5
6
7
8
9
10
11
12
void foo( double );

int main() {
  foo( 3.14 );
  return 0;
}

// note, this foo() is not used in this program
void foo( int x ) {
}

// error, where is void foo( double ) { /*code*/ } 
Topic archived. No new replies allowed.