remember to change your cout statements for each function btw
also yeah its not calculating right because the logic is incorrect. what youre doing in the findaverage function is
declaring average as double
average = the first number in the array grade
for loop starting at 0 going til 9 at increments of one
then this is where im seeing the biggest error, your if statement. what you wrote was:
assign grade[counter] to grade[counter] + average/NUM_GRADES
if this all comes back true then iterate (execute) the statements
or if it comes back false then dont.
thats what if statements do.
if (true) then lets do it
if (false) then lets NOT do it
in this case and how you wrote your if statement, it'll always iterate
well thats not whatcha want right?
you just want to add up all the elements in the array and then divide them by NUM_GRADES. thats all
1 2 3 4 5 6 7 8 9 10 11 12
|
void findAverageGrade (double grade[], int NUM_GRADES)
{
double average = 0;
for (int counter = 0; counter < NUM_GRADES; counter++)
{
____________________________;
}
_____________________________;
cout << "The average grade is " << average <<endl;
|
here you go, you just need two lines of code