只是想制作一个掷硬币的游戏,但也试图使等于随机数 0 或 1 的硬币转换为字符串类型“正面”或“反面”。编程新手,所以请不要判断它是否看起来很业余。谢谢你。
namespace TestCoin2
{
class Program
{
static void Main(string[] args)
{
int coin;// this will hold my random int numbers.
string userInput;// This will hold all my user input/ answers.
Console.WriteLine("Hello, Pick Heads or Tails:");
userInput =Console.ReadLine();
Random rng = new Random();
coin = rng.Next(0, 2);
string myString2;
string myString;
if (coin == 0)
{
myString = coin.ToString("heads");
}
else if (coin == 1)
{
myString2 = coin.ToString("tails"); <error under myString2
}
if (myString && userInput == "heads")
{
Console.WriteLine("You picked Right! Heads! YOU WIN!");
}
else if (coin == 1 && userInput == "Tails")
{
Console.WriteLine("You picked Right! Tails! YOU WIN!");
}
else
{
Console.WriteLine("You picked Wrong! it was..." + myString); <error
}
Console.ReadLine();
}
}
}