Need Help with Grade Calculator Program

Hello,

I'm trying to develop a quickgrade calculator program to compute the average of student grades. Here's the code snippet I have so far:

int[] gradesArray = {88, 90, 84, 70, 95, 78, 82, 74, 89, 91};
int sum = 0, index = 0;
while (index < gradesArray.length) {
    sum += gradesArray[index];
    index++;
}
int average = sum / gradesArray.length;
System.out.println("The calculated average is: " + average);

I'm puzzled about why it isn't functioning as expected. Can anyone identify any issues or provide suggestions for improvement?

Please post a complete it compiles and we can try it ourselves sketch.

I don't see how that even compiles. What does it do that it should not, or not do that it should?

a7

sounds like a program in Java...

are you in the right forum?

or...

int gradesArray[]

Please post all the code, using code tags. Very little of the snippet makes sense.

look this over

int gradesArray [] = {88, 90, 84, 70, 95, 78, 82, 74, 89, 91};
const int nGrades = sizeof(gradesArray)/sizeof(int);

void
grade (
int  *grades,
int   nGrades )
{
    int  sum = 0;
    for (int n = 0; n < nGrades; n++)  {
        sum += grades [n];
        Serial.print (grades [n]);
        Serial.print (", ");
    }
    float avg = sum / nGrades;

    Serial.print (", sum ");
    Serial.print (sum);
    Serial.print (", cnt ");
    Serial.print (nGrades);
    Serial.print (", avg ");
    Serial.println (avg, 1);
}


void
setup ()
{
    Serial.begin (9600);
    grade (gradesArray, nGrades);
}

void
loop ()
{
}

but presumably you need something you can enter to the program without changing the values in gradesArray

1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.