这段代码对我有用,除了它只检查一次重复,如果用户再次输入相同的整数,程序将第二次接受它。无论用户输入多少次,如何使该程序不接受输入?
int[] shippedOrderNumbers = new int[5];
Console.WriteLine("Please Input first Shipping Number: ");
shippedOrderNumbers[0] = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Please Input second Shipping Number: ");
shippedOrderNumbers[1] = Convert.ToInt32(Console.ReadLine());
if (shippedOrderNumbers[0] == shippedOrderNumbers[1])
{
Console.WriteLine("A dublicate number is not allowed please try again: ");
shippedOrderNumbers[1] =Convert.ToInt32(Console.ReadLine());
}
Console.WriteLine("Please Input third Shipping Number: ");
shippedOrderNumbers[2] = Convert.ToInt32(Console.ReadLine());
if (shippedOrderNumbers[0] == shippedOrderNumbers[2] || shippedOrderNumbers[1] == shippedOrderNumbers[2])
{
Console.WriteLine("A dublicate number is not allowed please try again: ");
shippedOrderNumbers[2] = Convert.ToInt32(Console.ReadLine());
}
Console.WriteLine("Please Input fourth Shipping Number: ");
shippedOrderNumbers[3] = onvert.ToInt32(Console.ReadLine());
if (shippedOrderNumbers[0] == shippedOrderNumbers[3] || shippedOrderNumbers[1] == shippedOrderNumbers[3] || shippedOrderNumbers[2] == shippedOrderNumbers[3])
{
Console.WriteLine("A dublicate number is not allowed please try again: ");
shippedOrderNumbers[3] = Convert.ToInt32(Console.ReadLine());
}
Console.WriteLine("Please Input fifth Shipping Number: ");
shippedOrderNumbers[4] = Convert.ToInt32(Console.ReadLine());
if (shippedOrderNumbers[0] == shippedOrderNumbers[4] || shippedOrderNumbers[1] == shippedOrderNumbers[4] || shippedOrderNumbers[2] == shippedOrderNumbers[4] || shippedOrderNumbers[3] == shippedOrderNumbers[4])
{
Console.WriteLine("A dublicate number is not allowed please try again: ");
shippedOrderNumbers[4] = Convert.ToInt32(Console.ReadLine());
}