Help : error C2059: syntax error : 'constant'

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Chrizo
    New Member
    • Oct 2008
    • 1

    Help : error C2059: syntax error : 'constant'

    Hi,

    I am new to C++ and I cannot seem to figure out what is wrong with my code. It looks fine to me but when I try to create an object of class Location I get this error which I do not understand the meaning to. Could someone please help me explain this problem?

    Thank you

    Chris


    #include<stdio. h>

    #include <math.h>

    double findAverage (double [], double);

    double findmax (double [], double);

    double findmin (double [], double);

    int main ()

    {

    double avg;

    //double max, min;

    /* max is to used for the Highest grade

    min for the lowest grade

    avg for the average grade

    dif for the deviation */



    #define SIZE 11

    double grades[SIZE]={89,94,19.67,7 8,89,37,34,67,9 0,87};



    avg=findAverage (grades, 11);

    int i;





    for (i=0; i < 11; i++)

    {

    printf("Grade\t Deviation\n -----\t ---------\n &%lf\t %lf\n",grades[i], grades[1]-avg);

    }



    printf("Average = %lf\n Highest Grade = %lf\n Lowest Grade = %lf",avg,findma x(grades, SIZE),findmin(g rades, SIZE));



    return 0;

    }



    double findAverage(dou ble value[],const, SIZE = 11)

    {

    int i;

    double sum=0.0;



    for (i=0; i<11; i++) /* Sum of Grades */

    sum= sum+value[i];

    return (sum/11); /* Calculates and returns the average */

    }



    double findmax(int vals[], double numels)

    {

    int i,max=vals[0];

    for (i=1; i<numels;i++)

    if (max < vals[1])

    max=vals[i];

    return (max);

    }



    double findmin(int vals[], double numels)

    {

    int i,min=vals[0];

    for (i=1; i<numels;i++)

    if (min > vals[1])

    min=vals[i];

    return (min);

    }
  • newb16
    Contributor
    • Jul 2008
    • 687

    #2
    It's not fair to give us less information that you have. I for one don't see any occurence of 'Location' in given code, nor there is any 'constant' word or line number info on which compiler object. However
    double findAverage(dou ble value[],const, SIZE = 11)
    this is wrong, maybe you meant something like
    double findAverage(dou ble value[], int size = 11)

    Comment

    • Walter Thizo
      New Member
      • Oct 2008
      • 13

      #3
      when i try to test you code ,it generate more than one error such as this ones :
      [C++ Error] Unit1.cpp(63): E2356 Type mismatch in redeclaration of 'findAverage(do uble *,double)'
      [C++ Error] Unit1.cpp(5): E2344 Earlier declaration of 'findAverage(do uble *,double)'


      for the error Type mismatch it caused by function

      [double findAverage (double [], double);]

      it does n't match with argument where your fuction has been implemented

      double findAverage(dou ble value[],const, SIZE = 11)


      for error Earlier declaration - i don't if i am wright but that is my suggestion ,declare your function inside the main () or don't declare it all as you declared during function implementation

      try it

      Comment

      • boxfish
        Recognized Expert Contributor
        • Mar 2008
        • 469

        #4
        Ummm... Don't declare your function inside main. But yes, what you need to do to get rid of the errors is make all the variables the right type and make sure the types on the function declarations match those on the headers of the function definitions. min and max are the wrong type. You have declared them as ints, but your program keeps assigning double values to them from the vals array. They need to be doubles. And you seem to be confused about the syntax when you write
        const, SIZE = 11
        You need to change the name of the function argument SIZE, because SIZE represents the number 11, which is not a valid name for a function argument. Your compiler sees
        const, 11 = 11
        You also need to get rid of the comma and give the argument a type other than const. And use the SIZE constant instead of the number 11. Something like
        const int valSize = SIZE
        And then use it in your function rather than just using the number 11. And do make the declarations (before main) match the headers on the definitions (after main).
        I almost forgot. Please use code tags around your code. Put [CODE] before it and [/CODE] after it, or click the # button above the message, so that it shows up in a box with a monospace font and the indentation doesn't get wrecked.
        Hope this helps.

        Comment

        Working...