Need help, I'm very close!!

This is so far what I got for the output. The Exp is the right output for the test. So when I run my program through textBed it gives me the result 87 which I wanted %88. I'm very close but I still need an advice. Thank you so much!

int main()
{

getGrades();
getAverage();

return 0;
}


int getGrades()
{
int grades[10];

for (int i = 1; i <= 10; i++)
{
cout << "Grade " << i << ": "; //prompts user for grades
cin >> grades[i]; // adds values to array
}
}



int getAverage()
{
int grades[10];
int average;
int sum = 0;
int count = 0;

cout << "Average Grade: " << average
<< "%"
<< endl;

for (int i = 0; i <= 10; i++)
{
if (grades[i] > 0)
sum += grades[i];
}
average = (count / 10);
if (average == 0)
count++;
return -1;
}



Started program
> Grade 1: 90
> Grade 2: 86
> Grade 3: 95
> Grade 4: 76
> Grade 5: 92
> Grade 6: 83
> Grade 7: 100
> Grade 8: 87
> Grade 9: 91
> Grade 10: -1
> Average Grade: 87%\n
Exp: Average Grade: 88%\n
Program terminated successfully

Started program
> Grade 1: 90
> Grade 2: 86
> Grade 3: 95
> Grade 4: -1
> Grade 5: 92
> Grade 6: 83
> Grade 7: 100
> Grade 8: 87
> Grade 9: 91
> Grade 10: 76
> Average Grade: 87%\n
Exp: Average Grade: 88%\n
Program terminated successfully

Started program
> Grade 1: -1
> Grade 2: -1
> Grade 3: -1
> Grade 4: -1
> Grade 5: -1
> Grade 6: -1
> Grade 7: -1
> Grade 8: -1
> Grade 9: -1
> Grade 10: -1
> Average Grade: -1%\n
Exp: Average Grade: ---%\n
Program terminated successfully
can you use code tags please?

This:
for (int i = 1; i <= 10; i++)
is not populating your 10-element array correctly. (element index starts at 0, not 1)

But the main issue is that both of your functions contain completely separate arrays, so when you call getAverage() it will not use the information you've gathered from the user in getGrades()

In fact, going by the code you've posted, I'm not sure how you've gotten that ouput?

Also:
return -1;
why return -1 for a function that's supposed to calculate an average?
Last edited on
I got it Thank you so much!!

Topic archived. No new replies allowed.