33选6
while (true) { Console.WriteLine("请输入你预测的中奖号码:"); int sum = 0; int a1 = int.Parse(Console.ReadLine()); int a2 = int.Parse(Console.ReadLine()); int a3 = int.Parse(Console.ReadLine()); int a4 = int.Parse(Console.ReadLine()); int a5 = int.Parse(Console.ReadLine()); int a6 = int.Parse(Console.ReadLine()); Console.Write("\n"); int[] arr = new int[6]; for (int i = 0; i < 6; i++) { Random r = new Random(); arr[i] = r.Next(1, 33); #region==判断是否相等,相等跳出重来== for (int j = 0; j < i; j++) { if (arr[j] == arr[i]) { i--; break; } } #endregion } foreach (int a in arr) { Console.WriteLine(a); if (a1 == a) sum += 1; if (a2 == a) sum += 1; if (a3 == a) sum += 1; if (a4 == a) sum += 1; if (a5 == a) sum += 1; if (a6 == a) sum += 1; } if (sum == 0) Console.WriteLine("你猜中了0个数,未中奖"); if (sum == 1) Console.WriteLine("你猜中了1个数,未中奖"); if (sum == 2) Console.WriteLine("你猜中了2个数,恭喜获得五等奖,奖金5元"); if (sum == 3) Console.WriteLine("你猜中了3个数,恭喜获得四等奖,奖金200元"); if (sum == 4) Console.WriteLine("你猜中了4个数,恭喜获得三等奖,奖金3000元"); if (sum == 5) Console.WriteLine("你猜中了5个数,恭喜获得二等奖,奖金250000元"); if (sum == 6) Console.WriteLine("你猜中了6个数,恭喜获得一等奖,奖金5000000元"); Console.Write(""); Console.ReadLine(); }