我正在制作一个游戏,让用户猜测 3 次,如果用户猜对了数字,那么他们将赢得一辆车。我还希望用户只有 3 次尝试。
static void Main(string[] args)
{
double numberToGuess = 3595.96;
double userGuess = 0;
while (userGuess != numberToGuess)
{
Console.Write("Enter your price guess: ");
userGuess = Convert.ToDouble(Console.ReadLine());
if (userGuess > numberToGuess)
{
Console.WriteLine("£{0} is too high!", userGuess);
}
else if (userGuess < numberToGuess)
{
Console.WriteLine("£{0} is too low!", userGuess);
}
else
{
Console.WriteLine("£{0} is right! Congratulations.", userGuess);
}
} Console.ReadKey();
}