所以我需要和学生做一个数组循环上课。输入必须在0到100之间,否则它将不接受用户的输入。
Console.WriteLine("How many students?");
int num1 = Keyboard.ReadInt();
int[] array = new int[num1];
Console.WriteLine("Give the student grades: ");
for (int i = 0; i < array.Length; i++)
{
int wrong;
wrong = Keyboard.ReadInt();
if (wrong > 0 && wrong <= 100)
{
array[i] = wrong;
}
else
{
while (wrong < 0 && wrong >= 100)
{
Console.WriteLine("Wrong input:");
wrong = Keyboard.ReadInt();
}
}
最佳答案
while (wrong < 0 || wrong >= 100) ...
一个数字不能同时小于零和大于99。
关于c# - C#如何更正数组中的错误输入,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/20243732/