编写一个程序帮助小学生学习乘法,用Random对象产生两个一位正整数如6和7,然后输入下列问题:

2025-12-05 23:57:58
推荐回答(1个)
回答1:

class Program
{
static void Main(string[] args)
{
string questFormat = "How much is {0} times {1}?";
string rightStr = "Very good! Excel lent! Nice work! Keep up the good work!";
string[] wrongStr = new string[] { "No, Please try again.", "Wrong, Try once more.", "Don’t give up!", "No, Keep trying." };
Random random = new Random();
while (true)
{
int a = random.Next(0, 10);
int b = random.Next(0, 10);
int c = 0;
while (true)
{
Console.WriteLine(questFormat, a, b);
if (int.TryParse(Console.ReadLine(), out c))
{
if (c == a * b)
{
Console.WriteLine(rightStr);
break;
}
}
Console.WriteLine(wrongStr[random.Next(0, 4)]);
}
}
}
}