I cant get my second if statement to work like expected. It is adding data into the array even though it's validated as incorrect. For example: The console prompts;
Enter Score: 1 for student: 1
Then if 500 is entered, the following prompt appears:
Please enter a value between 0 and 100.
Enter Score: 2 for student 1.
It is not holding it at "Score 1" for correct data to be entered.
I don't understand why because the 1st if statement works like that, keeping the array at [0,0] until correct data is entered.
static bool IsInRange (int input)
{
return input >= 0 && input <= 100;
}
for (int studentIndex = 0; studentIndex < studentCount; studentIndex++)
{
for (int scoreIndex = 0; scoreIndex < scoreCount; scoreIndex++)
{
int parsedScore = -1;
string score = string.Empty;
while(!IsNumeric(score) && !IsInRange(parsedScore))
{
Console.WriteLine("Enter score: {0} for student: {1}", scoreIndex + 1, studentIndex + 1);
score = Console.ReadLine();
if (!IsNumeric(score))
{
Console.WriteLine(string.Empty);
Console.WriteLine("Please enter a numeric value.");
continue;
}
parsedScore = Convert.ToInt32(score);
if (!IsInRange(parsedScore))
{
Console.WriteLine(string.Empty);
Console.WriteLine("Please enter a value between 0 and 100");
}
studentScores[studentIndex, scoreIndex] = parsedScore;
}
}
}