Help with array program

I need to write a program that prompts the user for 10 grades and then find the average. I have that part but I need to average to not include -1. How can I tell the program to not calculate -1 into the average.

#include <iostream>
using namespace std;

int main()
{
//Declare variables
float grade[10]; // 10 array slots
int count;
float total = 0;
double average;

for (count = 1; count <= 10; count++)
{
cout << "Grade " << count << ": ";
{
cin >> grade[count];
}
}

for (count = 1; count <= 10; count++)
total = total + grade[count];
average = total / 10;
cout << "Average Grade: " << average << "%" << endl; //Output of average


return 0;
}
1
2
for (count = 1; count <= 10; count++)
total = total + grade[count];


This will not work. Your array looks like this "float grade[10]; Then the only valid indices are : 0,1,2,...,9 (not 10 like you are using).

The for loop should look like this - for (count = 0; count < 10; count++)

Same with the first for-loop. Should look exactly the same as the other one.

Also, double average; calculates the average of the grades. not the percentages. So this -

"%" << endl; //Output of average Doesnt make much sense.
Last edited on
Topic archived. No new replies allowed.