#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2003
    Location
    New York
    Posts
    8
    Rep Power
    0

    Arrays + functions


    Last one for the evening:
    Trying to find a maximum value in an aray, by passing the array to a function and returning the value:
    PHP Code:
    double MaxGrade (int NumStudentsdouble FinalGrade[]);
    double MinGrade (int NumStudentsdouble FinalGrade[]);
    const 
    SIZE=35;
    void main(void)
    {
    //Assume array FinalGrade[SIZE] is filled with values

    double FinalGrade[SIZE];
    cout <<"The maximum grade is:" << MaxGrade (NumStudentsFinalGrade) << endl;
    cout <<"The minimum grade is:" << MinGrade (NumStudentsFinalGrade) << endl;
    }
    double MaxGrade (int NumStudentsdouble FinalGrade[])
    {
        
    //Declare variables
        
    double MaxGrade(0.0);
        
    int i(0);

        
    MaxGrade FinalGrade[i];

        for (
    i=0NumStudentsi++)
        
            if 
    FinalGrade[i] > MaxGrade
                MaxGrade 
    FinalGrade[i];

        return 
    MaxGrade;

    }

    double MinGrade (int NumStudentsdouble FinalGrade[])
    {
    //Declare variables
        
    double MinGrade(0.0);
        
    int i(0);

        
    MinGrade FinalGrade[i];

        for (
    i=0NumStudentsi++)
            if 
    FinalGrade[i] < MinGrade
                MinGrade 
    FinalGrade[i];

        return 
    MinGrade;


    Compiler gives me a syntax error: Indentifier "FinalGrade" in both functions Min & Max Grade on the if statement line.
    Thanks for any pointers!
  2. #2
  3. Contributing User
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jan 2003
    Location
    USA
    Posts
    7,091
    Rep Power
    2222
    Where are the parentheses around the condition of the if-statements?

IMN logo majestic logo threadwatch logo seochat tools logo