help

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include <iostream>
using namespace std;
void averagescore(double);
void aboveaverage(int[]);

int main()
{
	int exam[10];
	int x, total;

	cout << "Enter 10 grades and I will average them and indicate how many scores are above average...";
	
	for (x = 1; x < 11; x++)
	{
		cin >> exam[x];
		total += exam[x];
	}
	averagescore(total);
	aboveaverage(exam);
	
	return 0;
}

void averagescore(double total)
{
	cout << "Your average is: " << total / 10 << endl;
}
void aboveaverage(int E[])
{
	int x, z;
	for (x = 0; x < 10; x++)
	{
		if (E[x] >= 90)
			z++;
}
	cout << z;
}


my code isnt working for some reason what do i do to fix tis error?, this program calculates averages using arrays...
1) Array indexes start from 0, not 1
1
2
3
4
for (int x = 0; x < 10; ++x) {
    cin >> exam[x];
    total += exam[x];
}
A couple of things I see so far...

The valid elements of an array with size [x] run from 0 to x-1. You're going out of bounds when you read values into your exam array at line 13.

Also - total is uninitialized, so it has some random garbage value in it when you start adding values into it at line 16.

Total is an integer, but you've defined your averagescore function to take a double.

Z is uninitialized with some random garbage value when you try to increment it at line 34.
Topic archived. No new replies allowed.