我最近开始学习 C#,并开始根据有关笑话的流程图 ( http://prntscr.com/jo656t )制作简单的程序。
然而,当我在关于“你想听另一个笑话吗?”的流程图的一部分时。我完全不知道如何循环这个。
这是代码。
class Program
{
static void Main(string[] args)
{
Console.BackgroundColor = ConsoleColor.Black;
Console.ForegroundColor = ConsoleColor.White;
string Name;
Console.WriteLine("What is your name? ");
Name = Console.ReadLine();
Console.Write(Name);
Console.Clear();
Console.WriteLine("What is your age?");
int Age = Convert.ToInt16(Console.ReadLine());
Console.Write(Age);
Console.Clear();
string[] jokes = new string[] { "Joke1", "Joke2", "Joke3", "Joke4" };
int upper = jokes.GetUpperBound(0);
int lower = jokes.GetLowerBound(0);
Random rnd = new Random();
int jk = rnd.Next(lower, upper + 1);
if (Age >= 16)
{
Console.WriteLine("Do you want to hear a joke?");
string option = Console.ReadLine();
if (option == "yes")
{
Console.WriteLine(jokes[jk]);
Console.Read();
Console.WriteLine("Do you want to hear another joke?");
string option2 = Console.ReadLine();
int i;
if (option2 == "yes")
{
i = 0;
}
else
{
i = 1;
}
do
{
Console.WriteLine(jokes[jk]);
Console.Read();
} while (i == 0);
}
else
{
Console.WriteLine("Have a nice day, " + Name);
Console.Read();
}
}
else
{
Console.WriteLine("What a pitty! You're too young to hear this joke!");
Console.Read();
Console.WriteLine("Have a nice day, " + Age);
}
}
我不知道,因为我完全被困在这一点上,我们将不胜感激。
三国纷争
红糖糍粑
相关分类