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