我需要你的帮助来完成这个练习。我需要为每个客户分发票。如果票多于客户,票将被添加到第一个客户,依此类推。
例子:
Enter ticket number: 10
Enter customer number: 5
结果:
customer#1 ticket#1 ticket#6
customer#2 ticket#2 ticket#7
customer#3 ticket#3 ticket#8
customer#4 ticket#4 ticket#9
customer#5 ticket#5 ticket#10
到目前为止,这是我的代码,只能满足客户的第一个循环,但后续的票是我的问题。
List<int> customerNumberList = new List<int>();
List<int> ticketNumberList = new List<int>();
Console.Write("Enter Numer of Tickets: ");
int ticketCount = int.Parse(Console.ReadLine());
Console.Write("Enter Number of Customer: ");
int customerCount = int.Parse(Console.ReadLine());
for(int i = 1; i <= ticketCount; i++)
{
ticketNumberList.Add(i);
}
for(int i = 1; i <= customerCount; i++)
{
customerNumberList.Add(i);
}
if(customerNumberList.Count == 1)
{
Console.WriteLine("Customer#1");
for (int i = 0; i < ticketNumberList.Count; i++)
{
Console.WriteLine("Ticket#" + ticketNumberList[i]);
}
}
else
{
for (int i = 0; i < customerNumberList.Count; i++)
{
Console.WriteLine("Customer#" + customerNumberList[i]);
for(int j = 0; j <ticketNumberList.Count; j++)
{
if(customerNumberList[i] == ticketNumberList[j])
{
Console.WriteLine("Ticket#" + ticketNumberList[j]);
}
}
}
}
谢谢大家
慕少森
相关分类