我正在上课,老师问我们是否可以解决这个问题。我现在已经看了几个小时,我找不到怎么做。
目标是displaymenu
只显示一次。该应用程序循环,以便您可以在不退出的情况下重复使用它。向displaymenu
用户显示选项以选择他们想要做什么。现在我认为这不是你们见过的最干净的代码,但我仍在学习——只做了一个星期。任何其他建议将不胜感激。
static void Main(string[] args)
{
string choice = "";
do {
**displayMenu();** // only want to display once
choice = getChoice();
}
while (choice != "10");
{
Console.ReadLine();
}
}
static void displayMenu()
{
Console.WriteLine("Which shape do you want to work with?");
Console.WriteLine("_____________________________________");
Console.WriteLine("Press 1 for a circle.");
Console.WriteLine("Press 2 for an equilateral triangle.");
Console.WriteLine("Press 3 for a square.");
Console.WriteLine("Press 4 for a pentagon.");
Console.WriteLine("Press 5 for a hexagon.");
Console.WriteLine("Press 6 for a heptagon.");
Console.WriteLine("Press 7 for a octagon.");
Console.WriteLine("Press 8 for a nonagon.");
Console.WriteLine("Press 9 for a decagon.");
Console.WriteLine("Press 10 to quit.");
}
static string getChoice()
{
string c = Console.ReadLine();
if (c == "1")
circle();
if (c == "2")
triangle();
if (c == "3")
square();
if (c == "4")
polygon(5);
if (c == "5")
polygon(6);
if (c == "6")
polygon(7);
if (c == "7")
polygon(8);
if (c == "8")
polygon(9);
if (c == "9")
polygon(10);
return c;
}