I have a program that takes two arrays. One is a persons name. the other is their test score and displays it. I have an if statement nested in the for loop used to fill the array that allows you to enter stop as a name and it will put a break in the loop so that if you have less thatn 20 students you can stop entering names and scores when you are done by simply typing stop.
My problem is when i type stop in the loop it ends the for loop and the next line in my code is to display the students names and scores back to you. it displays all the names correctly unitl it gets to the name stop. after stop it displays a bunch of random numbers. I don't want it to display these numbers i want it to only display up to the name stop
could someone please explain how i would stop it from doing this.
here is my code
int main()
{
const int ARRAYTIME = 20;
string studentNames[ARRAYTIME];
int scores[ARRAYTIME];
cout << "To end the loop enter 'stop' as student name and '-1' as score" << endl;
for (int i = 0; i < ARRAYTIME ; i++)
{
cout << "Enter student name: ";
cin >> studentNames[i];
cout << "Enter score: ";
cin >> scores[i];
cout << endl;
if (studentNames[i] == "stop" || scores[1] == -1)
{
break;
}
}
cout << endl;
for (int n = 0; n < ARRAYTIME; n++)
{
cout << studentNames[n] << endl;
cout << scores[n] << endl;
}
return 0;
how do i get it to only display up to the name stop
I'm new to c++ so if this is a dumb question sorry. Thanks for your help