Can't Compile. I kep getting an error message on line 5 saying expected intializer??

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
#include "stdDevFns.h"
#include <iostream>
#include <cmath>

using namespace std;

// Put the prototype for the function calcStdDev () here

bool calcStdDev (double [], int, double &, double &);

int main ()
{
	// DO: declare an array called grades that can store 25 double values
	
	double grades [MaxStudents];
	
	double stdDev=0.0, mean=0.0;
	bool success = true, quit = false;
	int numberStudents=0;
	
	do
	{
		cout << "How many students do you have? " << endl;
		cout << "Number must be between 2 and 25 (inclusive). Enter -1 to quit" << endl;
		cin >> numberStudents;
		if (numberStudents == -1)
			quit = true;
		else 
			quit = false;
		
		
	} while ((numberStudents < MinStudents || numberStudents > MaxStudents) && !quit);
	
	if (quit)
		cout << "Error! Invalid number of students. Quitting." << endl;
	else
	{
		// Use a for loop to enter data into the array
		
		for (int i=0; i < numberStudents; i++)
		{
			cout  << "Enter the grade for student " << i << ": ";
			cin >> grades [i];
		}
		
		cout << endl << "The grades for the class are : " << endl;
		
		// Use a for loop to display the grades for the students
		
		for (int i=0; i < numberStudents; i++)
		{
			cout  << "Student " << i+1 << " has a grade of: " << grades [i] << endl;
		}
		
		cout << endl;
		
		// Call the function calcStdDev () here 
		// capture the returned Boolean value in 'success'
		
		success = calcStdDev (grades, numberStudents, stdDev, mean);
		
		if (success) 
		{
			cout << "The standard deviation is " << stdDev << endl;
			cout << "The mean is " << mean << endl;		
		}
		else
			cout << "Error! Could not calculate standard deviation or mean." << endl;
	}
	
	cout << "Bye!" << endl;
	return 0;
	
}

// Definition of the function calcStdDev () 

bool calcStdDev (double inputArray [], int n, double & dev, double & avg)
{
	bool success = true;
	double total = 0.0, stdTotal=0.0;
	
	if (n >= MinStudents && n <= MaxStudents)
	{
		success = true;
		
		// calculate average grade
		for (int i=0; i < n; i++)
			total += inputArray [i];
		avg = total / n;
		
		// calculate standard deviation
		for (int i=0; i < n; i++)
			stdTotal += pow ((inputArray [i] - avg), 2);
		
		dev = sqrt (stdTotal / (n-1));
	
	}
	
	else 
		success = false;
	
	return success;
	
}

You're beyond me in many ways but you haven't initialized any variables, perhaps you have to declare bool differently at the top or something?
Line number?
but you haven't initialized any variables

What are you talking about? Only the array wasn't initialized.

@Smitty: what's in stdDevFns.h?
the stdDevFns.h is a header file that I created myself to use in the program.
The only thing I can think of from what you state.

Your missing a semi-colon in steDevFns.h.

When it comes back with an error like this you need to go through the header files because that is where the error was. It is telling you something isn't finished in the header files.
@Smitty: that I know. We'd need to see its contents.

@Azagaros: no. There's no trailing semicolon for preprocessor directives.
None of you stated that could be that simple. You were making is issue more complicated than it was. Let him solve the problem on his own. That is what learning to program is all about.
None of you stated that could be that simple.

That's not correct. Had you read the thread, you'd notice I pointed out that the header should be checked. And please, don't make this kind of silly comment again. This is a very friendly forum and that kind of attitude is not welcome here.

Also, the report button is meant to report abusive posts, not posts you dislike. When people misunderstand what you say you're supposed to either post a reply or ignore it.
When you start educating people let me know. One thing I see is you know how to cut and paste and make comment. Beyond that, Informative value you have none.

Yes I read the thread. None of you stated it could be that simple. Since clang has a better error reporting system than GCC, the error would take some parsing in the header file, which I don't need to see to know anything from the Error message given. These are exercises many of us have done while learning to program.

Of course, I would hope that the system headers would be in good standing order from their release time.

I don't need your commentary in stating the arrogance that you may have in being more experienced than I am. I did learn to program before the STL was part of C++. For me Writing things like the STL isn't hard.

You can ignore as simply as I can so move on.
I honestly hope that the more "advanced" features of the report button are available only to users with a significant post count in addition to time on their account... [/side_note]

I'd like to ++filipe, though, as it would be extremely helpful to see the header.

-Albatross
Topic archived. No new replies allowed.