Arrays end by sentinal

I have an array that i want to end when a -1 is put in. how do i get that to happen

#include <iostream>
using namespace std;

int main()
{
const int NUM_TEST = 100;
double score[NUM_TEST], test, total, average;


for (int test = 0; test <= NUM_TEST; test ++)
{
cout<< "Test " << ( test + 1) << " score is ";
cin>> score[test];
}
total += score[test];
average= total/(NUM_TEST);

system("pause");
return 0;
}
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
#include <iostream>
using namespace std;

int main()
{
	const int NUM_TEST = 100;
	double score[NUM_TEST], average;
	double total=0.0;
	int test;
	for (test = 0; test < NUM_TEST; test ++)
	{
		cout<< "Test " << (test+1) << " score is ";
		cin>> score[test];
		if(score[test] == -1)
		{
			break;
		}
		total += score[test];
	}
	
	average= total/test;
	cout << "total is " << total <<endl;
	cout << "average is:" << average << endl;
	system("pause");
	return 0;
}
Topic archived. No new replies allowed.