【发布时间】:2016-06-01 12:39:48
【问题描述】:
我还没有完全理解方法,我不知道为什么会发生这种情况......我试图让我的代码更改为单词,我认为这是要走的路。
namespace ConsoleApplication9
{
class Program
{
static void Main(string[] args)
{
Random r = new Random();
Console.WriteLine("Hi wanna play rock paper scissors?<press enter to continue>");
Console.ReadKey();
int user = 0;
int ai = r.Next(1, 4);
Console.WriteLine("Pick what youll show! (1-rock, 2-paper, 3-scissors) and press enter");
user = Convert.ToInt32(Console.ReadLine());
if (user > 3)
{
Console.WriteLine("ERROR! your number must be <= 3. <Press enter to close the program>");
goto end;
}
if (user == ai)
{
Console.WriteLine("Its a draw! <press enter to continue>");
goto end;
}
Console.WriteLine(user);
end:
Console.ReadKey();
}
public static string ntw (int user) //ntw: not all code paths return a value
{
if (user == 1)
return "rock";
if (user == 2)
return "paper";
if (user == 3)
return "scissors";
}
}
}
提前致谢。
【问题讨论】:
-
如果
user不是 1、2 或 3 怎么办? -
1.请不要使用
goto。 2 发布代码时,请仔细检查缩进的一致性和可读性。 -
你真的应该使用Dictionary 来处理这种事情。