-
compile errors
This file has both syntactic and semantic errors. I managed to fix a few, but im still having issues... The program should compute an average grade of 76 and a standard deviation of 13. I'm new to programming, and any assistance would be much appreciated!
#include <iostream.h>
#include <iomanip.h>
#include <math.h>
float find_avg(int [], int); // function prototype
float std_dev(int [], int, float); // function prototype
int main()
{
const int NUMELS = 10;
int values[NUMELS] = {98, 82, 67, 54, 78, 83, 95, 76, 68, 63};
float average, stddev;
float findAvg(int nums[], int numel)
average = findAvg(values, NUMELS); // call the function
stddev = stdDev(values, NUMELS, average); // call the function
cout << "The average of the numbers is "
<< setw(5) << setiosflags(ios::showpoint)
<< setprecision(2) << average << endl;
cout << "The standard deviation of the numbers is "
<< setw(5) << setiosflags(ios::showpoint)
<< setprecision(2) << stddev << endl;
return 0;
}
float findAvg(int nums[], int numel)
{
int i;
float sumnums = 0.0;
for (i = 0; i < numel; i++) // calculate the sum of the grades
sumnums = sumnums + nums[i];
return (sumnums / numel); // calculate and return the average
}
float stdDev(int nums[], int numel, float av)
{
int i;
float sumdevs = 0.0;
for (i = 0; i < numel; i++)
sumdevs = sumdevs + pow((nums[i] - av),2);
return(sqrt(sumdevs/numel));
}
-
1 thing
Fixed what I could but I am not familiar with setting precision and the other stuff you did
#include <iostream.h>
#include <iomanip.h>
#include <math.h>
float find_avg(int [], int); // function prototype
float std_dev(int [], int, float); // function prototype
int main()
{
const int NUMELS = 10;
int values[NUMELS] = {98, 82, 67, 54, 78, 83, 95, 76, 68, 63};
float average, stddev;
average = find_avg(values, NUMELS); // call the function
stddev = stdDev(values, NUMELS, average); // call the function
cout << "The average of the numbers is "
<< setw(5) << setiosflags(ios::showpoint)
<< setprecision(2) << average << endl;
cout << "The standard deviation of the numbers is "
<< setw(5) << setiosflags(ios::showpoint)
<< setprecision(2) << stddev << endl;
return 0;
}
float find_avg(int nums[], int numel)
{
int i;
float sumnums = 0.0;
for (i = 0; i < numel; i++) // calculate the sum of the grades
sumnums = sumnums + nums[i];
return (sumnums / numel); // calculate and return the average
}
float stdDev(int nums[], int numel, float av)
{
int i;
float sumdevs = 0.0;
for (i = 0; i < numel; i++)
sumdevs = sumdevs + pow((nums[i] - av),2);
return(sqrt(sumdevs/numel));
}
-
Thanks! Thanks! Thanks! :) i appreciate your efforts ;) !!!
You cut my errors in half, now there are only 2 left:
error C2065: 'stdDev' : undeclared identifier
error C2371: 'stdDev' : redefinition; different basic types
I replaced stdDev, with std_dev and stddev and got different errors like:
error C2064: term does not evaluate to a function
-But that probably does more harm than good!
I have no clue what to do with these stdDev lines (Standard Deviations)!
Instructions:
Determine the standard deviation by:
Substracting the average from each individual grade. (This results in a set of new numbers, each of which is called a deviation.)
Squaring each deviation found in the previous step.
Adding the squared deviations and dividing the sum by the number of deviations.
The square root of the number found in the previous step is the standard deviation.
-
Your function prototype and definition need to have the same name
float std_dev (int [], int, float); // function prototype
float stdDev(int nums[], int numel, float av)
{...
};
-
Wow, Works like a charm!
Thanks guys!!!