arrays

need to write a program that asks for up to 50 test scores entered on the same line separated by a space and ends when -1 is entered but the scores have to be 0-100 and need to convert to string to not directly read input to test for non numerics entered cant seem to figure this out please 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
38
39
40
41
42
43
44
45
46
#include <iostream>
using std::cin;
using std::cout;
using std::ios;
using std::string;
using std::endl;
#include <string>
#include <cstdlib>



int main()
{
  
  const int MAX_SCORE = 50; // the maximum #of scores that a user can enter
  int score[MAX_SCORE]; // create storage for up to 50 scores
  int nScores = 0; // count the number of scores entered
  
  
  // read the scores from the keyboard, space and/or newline delimited
	 cout << "Input up to 50 numbers (0-100) enter -1 after last value input: " << endl;
	 
  for (int i = 0; i < MAX_SCORE; i++)
  {
    cin >> score[i];
	
    if(cin.fail())
    {
 
      cin.clear();
	  cin.sync();
    } 
	
	else if (score[i] < 0)
	{ 
	 
   //proceed as normal
	
	break;	// enter no more scores after the 1st negative is found
	}
	else
	{
	nScores++; // count the score if it is non-negative
  }}
    cout << " The number of scores entered was: " << nScores << endl; // say how many scores entered 
}


tried using this but i think i need to convert from string such as atoi function but cant figure out how to separate all the entries to convert to multiple inputs so that the program will count how many test scores are entered?!
Topic archived. No new replies allowed.