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!
#include <iostream>
using std::cin;
using std::cout;
using std::ios;
using std::string;
using std::endl;
#include <string>
#include <cstdlib>
int main()
{
constint 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();
}
elseif (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?!