我在这段代码中面临的问题是循环的第一次迭代很好,但是在第二次迭代中,当我按下 y 时,程序会出错。错误 = 输入字符串的格式不正确。
错误行 = my = int.Parse(Console.ReadLine());
static void Main(string[] args)
{
int a, my;
char again = 'y';
while ((again == 'y' || again=='Y'))
{
Console.Write("Enter the value for your number = ");
my = int.Parse(Console.ReadLine());
Random b = new Random();
a = b.Next(1, 6);
if (a == my)
{
Console.WriteLine("Congratulations");
}
else
{
Console.WriteLine("you Lost");
Console.WriteLine("My no is {0}.", a);
}
Console.Write("Again? Then press 'y' or 'Y' = ");
again = (char)Console.Read();
}
Console.ReadLine();
}