整个程序的草稿,但是我试图使菜单正常工作,并且遇到了无法解决的问题。测试客户菜单的应用程序时,1-4会正确返回,但5不会。我希望5返回到主菜单,但它正在返回我的错误检查输出。同样的问题也出现在管理器菜单中,其中1-4可以正确返回,而5和6则不能。它们都将我也定向到我的错误检查输出。我该如何修改代码以使每个子菜单功能正常工作?
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 user is returned to the main menu
{
Console.WriteLine("Returning to main menu,thank you.");
}
while (customerChoice != 5)
{
if (customerChoice == 1)
{
Console.WriteLine("This shows movies available.\n"); // this option gives the user the opportunity to view all movies available to rent
//MoviesAvailable();
}
if (customerChoice == 2)
{
Console.WriteLine("This is 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("This is to show my rented movies.\n"); // this option gives the user the opportunity to view movies a user currently has rented,with email address
//MyRentedmovie();
}
if (customerChoice == 4)
{
Console.WriteLine("This is to return a movie.\n"); // this option gives the user the opportunity to return a movie rented
//Returnmovie();
}
customerChoice = CustomerMenuChoice();
if (customerChoice == 5)
{
Console.WriteLine("Returning to main menu,thank you.");
}
}
}
static int CustomerMenuChoice()
{
Console.WriteLine("Below 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 return to menu.");
Console.WriteLine("-----------------------------------------------------------------------------------------------------------");
string customerChoice2 = Console.ReadLine();
Console.WriteLine();
while (!(customerChoice2 == "1" || customerChoice2 == "2" || customerChoice2 == "3" || customerChoice2 == "4") || customerChoice2 == "5") // error checking
{
Console.WriteLine("Please enter a valid option: ");
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 return to menu.");
customerChoice2 = Console.ReadLine();
}
return int.Parse(customerChoice2);
}
static void ManagerMenu() {
int managerChoice = ManagerMenuChoice(); // Reading in the managerChoice into the ManagerMenuChoice method
if (managerChoice == 6) // if user enters 6,thank you.");
}
while (managerChoice != 6)
{
if (managerChoice == 1)
{
Console.WriteLine("This is to add a movie to inventory.\n"); // this option gives the manager the ability to add a movie to inventory
//Addmovie();
}
if (managerChoice == 2)
{
Console.WriteLine("This is to remove a movie from inventory.\n"); // this option gives the manager the ability to remove a movie from inventory
//RemoveMovie();
}
if (managerChoice == 3)
{
Console.WriteLine("This is to edit a movie from inventory.\n"); // this option gives the manager the ability to edit a movie to inventory
//EditMovie();
}
if (managerChoice == 4)
{
Console.WriteLine("This is to process a btach transaction file.\n"); // this option gives the manager the ability to process a batch transaction file
//BatchTransaction();
}
if (managerChoice == 5)
{
Console.WriteLine("This is to access the report menu.\n"); // this option gives the manager the ability to access the report menu
//ReportMenu();
}
managerChoice = ManagerMenuChoice();
if (managerChoice == 6)
{
Console.WriteLine("Returing to main menu,thank you.!"); // returns to main menu
}
}
}
static int ManagerMenuChoice()
{
Console.WriteLine("Below is a list of actions that can be performed by managers: ");
Console.WriteLine("\nPress 1 to add a new movie to to the inventory.");
Console.WriteLine("\nPress 2 remove a movie from inventory.");
Console.WriteLine("\nPress 3 to edit a movie in inventory.");
Console.WriteLine("\nPress 4 to process a btach transaction file.");
Console.WriteLine("\nPress 5 to access the report menu.");
Console.WriteLine("\nPress 6 to return to the menu.");
Console.WriteLine("-----------------------------------------------------------------------------------------------------------");
string managerChoice2 = Console.ReadLine();
Console.WriteLine();
while (!(managerChoice2 == "1" || managerChoice2 == "2" || managerChoice2 == "3" || managerChoice2 == "4") || managerChoice2 == "5" || managerChoice2 == "6") // error checking
{
Console.WriteLine("Please enter a valid option: ");
Console.WriteLine("\nPress 1 to add a new movie to to the inventory.");
Console.WriteLine("\nPress 2 remove a movie from inventory.");
Console.WriteLine("\nPress 3 to edit a movie in inventory.");
Console.WriteLine("\nPress 4 to process a btach transaction file.");
Console.WriteLine("\nPress 5 to access the report menu.");
Console.WriteLine("\nPress 6 to return to the menu.");
managerChoice2 = Console.ReadLine();
}
return int.Parse(managerChoice2);
}
}
}