program not compiling

hello i am working on this program for a class assignment, it does not compile I have been trying to figure it out. So far its like shooting in the dark. I am hoping someone here that is more advanced can look at and tell where I am screwing up at? Your help will be much appreciated.

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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
  /*
	
	
	Program Assignment:		Program 6
	Program Description:	Read data from file, calculate average, maximum value,
							minimum value, standard deviation, and display
							quartile summary.
*/

//Pre-processing Details
#include <iostream>
#include <iomanip>
#include <fstream>
#include <cmath>
using namespace std;

//Function Prototypes - take a good look at how these are defined
void readData(double[], int &);
double calcAvg(double[], int);
void calcMaxMin(double[], int, int &, int &);
double calcStdDev(double[], int, double);
void outputQuarSum(double[], int, int &, int &, int &, int &);

int main()
{
	//Declare Variables
		double numbers[500], avgNum = 0.0, stdDev = 0.0;
		int arraySize = 0, maxIndex = 0, minIndex = 0;
		int q1count = 0, q2count = 0, q3count = 0, q4count = 0;
		int maxNum = 0, minNum = 0;

	//Get data from file
		readData(numbers, arraySize);
		
	//Lets see if we have some data...
	    for (int i = 0; i < arraySize; i++)
	      cout << numbers[i] << ' ';  	
	//Use calcAvg() to assign average number
	double calcAvg(sales);	
		
	//Use calcMaxMin() to get index for maximum/minimum number
	calcMaxMin()
		

	//Get standard deviation from data using calcStdDev()
	data = calcStdDev();
		
		
	//Sort data into quartile summary using outputQuarSum()
	outputQuarSum(maximum, minimum)	
		
		
	//Output Final Summary
		cout << "                 SUMMARY                      " << endl;
		cout << "----------------------------------------" << endl;
		cout << right << fixed << showpoint << setprecision(1);
		cout << setw(20) << "Data Elements:" << setw(10) << arraySize << endl;
		cout << setw(20) << "Mean:" << setw(10) << avgNum << endl;
		cout << setw(20) << "Maximum:" << setw(10) << maxNum << endl;
		cout << setw(20) << "Minimum:" << setw(10) << minNum << endl;
		cout << setw(20) << "Standard Deviation:" << setw(10) << stdDev << endl;
		cout << setw(20) << "Quartile 1 Scores:" << setw(10) << q1count << endl;
		cout << setw(20) << "Quartile 2 Scores:" << setw(10) << q2count << endl;
		cout << setw(20) << "Quartile 3 Scores:" << setw(10) << q3count << endl;
		cout << setw(20) << "Quartile 4 Scores:" << setw(10) << q4count << endl;
		cout << "----------------------------------------" << endl;
		cout << "END OF JOB TERMINATION" << endl << endl;

	return 0;
}


//ReadData() Function Definition:	This function will read data from a file
//									and store it in an array.

	void readData(double numbers[], int &elemNums)
	{		
	//Declare Variables
		int count = 0;
		ifstream inputFile;

	//Open File
		inputFile.open("array_pgmdata.txt");

	//Read Data from File
		while (inputFile >> numbers[count])
			count++;
			
	//Assign the number of elements to elemNums
		elemNums = count;

	//Close File
		inputFile.close();
	}


//calcAvg() Function Definition:	This funtion will calculate the average of all numbers
//									in an array.
	
	double calcAvg(double numbers[], int elemNums)
	{
	//Declare Variables
	int array , numbers;	
	
	//Sum numbers[]...use a loop
	for (array = 0; array < (size -1); array++)
		
		
	//Return the average of all the numbers of the array
		
		
		
	}

//calcMaxMin() Function Definition:	This function will determine the index for the maximum
//									and minimum number of an array.

	void calcMaxMin(double numbers[], int elemNums, int &maxIndex, int &minIndex)
	{
	//Declare Variables
	int maxIndex, minIndex;	
	double maxValue, minValue;	
		
	//Calculate Maximum Value...find highest number...need a loop
	for (int start = 0; start , (size - 1); start++)	
	{
		maxIndex = start;
		maxValue = scores[start];
		for (int index = start + 1; ndex < size; index++)
		{
			if (scores[index] > maxValue)
			{
				maxValue = scores[index];
				MaxIndex = index;
			}
		}
		swap(scores[maxIndex], scores[start]);
		
		}	
		

	//Calculate Minimum Value...find lowest number...need a loop
	for (int start = 0; start , (size - 1); start++)	
		
		{
		minIndex = start;
		minValue = scores[start];
		for (int index = start + 1; index < size; index++)
		{
			if (scores[index] > minValue)
			{
				minValue = scores[index];
				MinIndex = index;
			}
		}
		swap(scores[minIndex], scores[start]);
		
		}		
		
	}

//calcStdDev() Function Definition:	This function will calculate standard deviation
//									from the calculated data.

	double calcStdDev(double numbers[], int elemNums, double avgNum)
	{
	//Declare Variables
		
		
	//Calculate Standard Deviation..implement std dev pseudocode in assignement...use a loop.
for i=0 to arraySize-1
sum = sum + (arrayVal[i] - avg)^2
standDev = sqrt((1.0/arraySize)*sum)
}
			
	//Finish calculating standard deviation and return value
		
		
	}

//outputQuarSum() Function Definition:	This function will display the number of
//										scores in each quartile.

	void outputQuarSum(double numbers[], int elemNums, int &q1count, int &q2count, int &q3count, int &q4count)
	{
	
	//Declare local variables..
	int number;
	double scores1,  scores2, scores3, scores4;	
		
		
	//Assign each score to the proper quartile...use a loop with if-else if structure
	for (int index = 0; index < eleNums; index++)
	{
		scores1 = q1count
		scores2 = q2count
		scores3 = q3count
		scores4 = q4count
	}
	cout << "quartile1" << q1count  << endl;
	cout << "quartile2" << q2count  << endl;
	cout << "quartile3" << q3count  << endl;
	cout << "quartile4" << q4count  << endl;	
		
		
		
	}





********************************************************************************************************************************************************************************************************************************************************************************************************************************
here is the file data from the file(array_pgmdata.txt) it is supposed to read from.

<tag>
86
68
19
79
46
66
55
61
45
55
49
44
52
67
45
23
33
34
17
88
93
67
56
19
43
67
98
36
24
78
61
12
21
11
33
95
91
82
73
37
28
19
16
17
15
14
33
18
21
6
47
4
58
45
48
37
83
68
36
91
83
90
8
77
79
82
50
15
49
45
5
15
48
61
48
30
29
45
73
35
43
45
63
89
87
93
81
6
98
9
89
12
78
15
16
17
85
88
79
93
82
94
91
93
77
66
55
44
84
54
41
35
42
82
11
44
91
47
50
41
32
83
87
45
14
48
37
93
44
67
41
50
44
45
40
43
39
66
77
93
29
42
39
46
22
21
40
77
44
66
77
88
23
91
82
73
64
56
47
37
5
66
7
88
67
32
38
81
72
88
34
66
66
9
88
75
23
11
66
88
33
25
24
18
38
71
44
53
86
23
68
21
99
77
67
78
98
23
45
54
76
23
86
22
52
8
31
81
45
54
23
81
64
94
87
34
77
66
55
85
76
67
58
99
87
78
56
75
67
98
88
83
72
91
93
56
67
89
98
87
55
66
77
88
78
98
87
67
3
75
97
12
45
65
87
23
65
98
8
22
33
78
6
15
27
38
5
6
9
2
99
88
55
12
23
43
4
32
87
67
45
3
8
4
7
4
85
34
45
75
13
85
6
4
8
4
87
21
12
23
34
84
52
53
66
88
44
23
91
82
27
73
56
33
73
8
3
2
8
47
35
98
34
76
57
35
87
23
67
99
11
22
54
23
34
45
87
11
5
7
9
3
7
44
66
23
75
98

</tag>
Last edited on
Have you even tried to read the compiler error messages?
Mnay of them are quite straight forward.
Here aree some fixes to get you started.

Line 39: 'sales' is undefined. You must define variables before
you can use them.

Line 42: According to your forward declaration, calcMaxMin takes 4 arguments.
You must pass 4 arguments here.

Line 42: statement requires a terminating semicolon.

Line 46: calcStdDev requires 4 arguments.

Line 50: maximum, minimum are not defined.

Line 50: Statement requires a terminating semicolon.

Make the fixes, recompile and fix more errors. Rinse and repeat.
If something isn't compiling, you should tell us what the compilation errors are. Usually, the first one is the most important, and you try to whittle down the compiler errors one at a time.

You should compile early, compile often. If you keep adding new code onto old code that doesn't work, you are just digging a deeper hole for yourself, and you will have to pay for it eventually.

First error (first number is the line number)
39:17: error: 'sales' was not declared in this scope
double calcAvg(sales);
This is not calling the function. This is syntactically a function declaration. Second, calcAvg expects two arguments, but you are only giving it one. Third, sales is not a variable that I see. Did you mean to use your 'numbers' array?

It would be something more like:
avgNum = calcAvg(numbers, arraySize);

Of course, there are other problems besides this. Your calcAvg function itself clearly isn't finished. The for loop has no body, and you don't have a return statement.

I suggest reading some tutorials:
http://www.cplusplus.com/doc/tutorial/control/
http://www.cplusplus.com/doc/tutorial/functions/
Last edited on
For readData(), you're not checking that the file has been opened OK. Also you don't need to close the file as it will be closed when inputFile goes out of scope. You don't need the variable count. You can just use elemNums. Possible (not tried):

1
2
3
4
5
6
void readData(double numbers[], int &elemNums) {
    elemNums = 0;

    if (ifstream inputFile("array_pgmdata.txt"))
        while (inputFile >> numbers[elemNums++]);
}


Also you should also pass to the function the maximum size of elemNums - or have this value defined as a global const. Then you can check that the size of the array is not exceeded when values are inserted.

The calling function should check that the value of elemNums is not 0 as if it is 0 then an error occurred.
Topic archived. No new replies allowed.