我正在尝试创建一个菜单,该菜单将首先以用户身份出现,如果他或她是客户或经理(或退出该程序)。用户选择了客户或经理后,将出现另一个子菜单,其中包含可在客户或经理下执行的操作。出现两个相同的错误,分别针对两行不同的代码指出“名称空间不能直接包含诸如字段或方法之类的成员”。我已经看了几个小时,只是被困住并寻找解决方案。
class Program
{
static void Main(string[] args)
{
Mainmenu();
Console.ReadKey();
}
static void Mainmenu()
{
int userChoice = MainmenuChoice(); // Reading in the userChoice with the MenuChoice method
if (userChoice == 3) // if user enters 3,the program ends
{
Console.WriteLine("Thank you,Goodbye!");
}
while (userChoice != 3)
{
if (userChoice == 1)
{
Console.WriteLine("Welcome to the customer menu!\n"); // The customer menu is brought up if user enters 1
CustomerMenu();
}
if (userChoice == 2)
{
Console.WriteLine("Welcome to the manager menu!\n"); // The manager menu is brought up if user enters 2
//ManagerMenu();
}
userChoice = MainmenuChoice(); // program ends
if (userChoice == 3)
{
Console.WriteLine("Thank you for visiting VideoMart at University Boulevard,Goodbye!");
}
}
}
static int MainmenuChoice()
{
Console.WriteLine("-----------------------------------------------------------------------------------------------------------"); // introducing the user with the menu
Console.WriteLine("Welcome to VideoMart at University Boulevard! \nAt VideoMart you are able to rent a variety of movies from many genres such as action,family,horror,etc!");
Console.WriteLine("\nPress 1 if you are a customer");
Console.WriteLine("\nPress 2 if you are a manager");
Console.WriteLine("\nPress 3 to Exit");
Console.WriteLine("-----------------------------------------------------------------------------------------------------------");
string choice = Console.ReadLine();
Console.WriteLine();
while (!(choice == "1" || choice == "2" || choice == "3")) // error checking
{
Console.WriteLine("Please try again");
Console.WriteLine("Press 1 if you are a customer");
Console.WriteLine("Press 2 if you are a manager");
Console.WriteLine("Press 3 to Exit");
choice = Console.ReadLine();
}
return int.Parse(choice);
}
}
static void CustomerMenu() {
int customerChoice = CustomerMenuChoice(); // Reading in the customerChoice into the CustomerMenuChoice method
if (customerChoice == 5) // if user enters 5,the program ends
{
Console.WriteLine("Thank you for using VideoMart,goodbye.");
}
while (customerChoice != 5)
{
if (customerChoice == 1)
{
Console.WriteLine("Press 1 to view movies available to rent.\n"); // this option gives the user the opportunity to view all movies available to rent
//MoviesAvailable();
}
if (customerChoice == 2)
{
Console.WriteLine("Press 2 to rent a movie.\n"); // this option gives the user the opportunity to rent a movie,with email address
//RentMovie();
}
if (customerChoice == 3)
{
Console.WriteLine("Press 3 to view a list of movies you currently have rented.\n"); // this option gives the user the opportunity to view movies a user currently has rented,with email address
//RentMovie();
}
if (customerChoice == 4)
{
Console.WriteLine("Press 4 to return a movie rented.\n"); // this option gives the user the opportunity to return a movie rented
//RentMovie();
}
customerChoice = CustomerMenuChoice();
if (customerChoice == 5)
{
Console.WriteLine("Thank you for visiting VideoMart at University Boulevard,Goodbye!");
}
}
}
static int CustomerMenuChoice()
{
Console.WriteLine("-----------------------------------------------------------------------------------------------------------"); // Menu for the customer option
Console.WriteLine("Welcome to VideoMart at University Boulevard! \nBelow is a list of actions that can be performed by customers!");
Console.WriteLine("\nPress 1 to view movies available to rent.");
Console.WriteLine("\nPress 2 to rent a movie.");
Console.WriteLine("\nPress 3 to view a list of movies you currently have rented.");
Console.WriteLine("\nPress 4 to return a movie rented.");
Console.WriteLine("\nPress 5 to exit.");
Console.WriteLine("-----------------------------------------------------------------------------------------------------------");
string customerChoice2 = Console.ReadLine();
Console.WriteLine();
while (!(customerChoice2 == "1" || customerChoice2 == "2" || customerChoice2 == "3" || customerChoice2 == "4") || customerChoice2 == "5") // error checking
{
Console.WriteLine("\nPress 1 to view movies available to rent.");
Console.WriteLine("\nPress 2 to rent a movie.");
Console.WriteLine("\nPress 3 to view a list of movies you currently have rented.");
Console.WriteLine("\nPress 4 to return a movie rented.");
Console.WriteLine("\nPress 5 to exit.");
customerChoice2 = Console.ReadLine();
}
return int.Parse(customerChoice2);
}
}