Thread: compile errors

  1. #1
    Registered User
    Join Date
    Dec 2001
    Posts
    3

    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));
    }

  2. #2
    Unregistered
    Guest

    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));
    }

  3. #3
    Registered User
    Join Date
    Dec 2001
    Posts
    3
    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.
    Last edited by spider; 12-10-2001 at 10:40 PM.

  4. #4
    Registered User
    Join Date
    Nov 2001
    Posts
    30
    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)
    {...
    };
    Homer

    D'OH!

    mmmmmmmm... iterations

  5. #5
    Registered User
    Join Date
    Dec 2001
    Posts
    3
    Wow, Works like a charm!
    Thanks guys!!!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Strange compile errors
    By csonx_p in forum C++ Programming
    Replies: 10
    Last Post: 07-28-2008, 11:41 AM
  2. compile once, compile twice ...error
    By Benzakhar in forum Windows Programming
    Replies: 6
    Last Post: 12-28-2003, 06:00 AM
  3. Stupid compiler errors
    By ChrisEacrett in forum C++ Programming
    Replies: 9
    Last Post: 11-30-2003, 05:44 PM
  4. executing errors
    By s0ul2squeeze in forum C++ Programming
    Replies: 3
    Last Post: 03-26-2002, 01:43 PM