half empty array

hellow every one,i have a question i have an array which have some index are empty and they are in the last of course,so i want to compute the average of all the indexs put i dont now when to stop the loop since the lenth of the array is 50
this is my code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
void averagescore(int scores[50])
{
	int total=0;
	int x=0;
	for(int i=0;i<=50;i++)
	{
		total =total+ scores[i];
		x++;
		if (scores[i]='\n')//realy i didnt know what to put in the condition so i did this
			break;

}
	cout<< "the average of the scores" <<total/x<<endl<<x<<endl;//after all of this the loop reads only the first index and get the avrage of it
}

these are the index of the array :88 87 88 66 55 56 75 75 78 80 80 90 99 87 44 34 0 100
is there any suggestions!!!
Last edited on
Hello again.

1. you could set a variable Counter to store the amount of elements of the array which were assigned to; then use condition i<Counter in the for loop

or

2. assign the rest of the elements, which were previously not assigned to, with zeros

or

3. initialize all elements of the array with zeros before assigning any values

or

4. use a vector instead of an array

EDIT:
these are the index of the array :88 87 88 66 55 56 75 75 78 80 80 90 99 87 44 34 0 100

These are rather values stored in the array then indexes.
Last edited on
thank you allot again ^_______^
and about the index thanks again for correting the info
best wiches;
Topic archived. No new replies allowed.