银行系统转换报表
Switch Statement for Banking System
嗨,我是新手,我正在尝试找出一种方法,让客户可以从 DisplayMenu 输入他们选择的选项,然后将他们带到另一个屏幕,如 DisplayBalance(),这是目前正在运行的。但随后我希望他们按下回车键,然后 return 他们回到 DisplayMenu() 并能够输入另一个选项将他们带到另一个屏幕,但目前正在发生的是控制台退出。有谁知道如何解决这个问题?
// 显示菜单
private static void DisplayMenu()
{
Console.WriteLine("Welcome to your online bank account\nPlease choose from the options below: ");
Console.WriteLine("");
Console.WriteLine("1.View Client Info");
Console.WriteLine("");
Console.WriteLine("2. View Account Balance:");
Console.WriteLine(" 2A.Everyday\n 2B.Investment\n 2C.Omni");
Console.WriteLine("");
Console.WriteLine("3.Deposit Funds:\n 3A.Everyday\n 3B.Investment\n 3C.Omni");
Console.WriteLine("");
Console.WriteLine("4.Withdraw Funds:\n 4A.Everyday\n 4B.Investment\n 4C.Omni");
Console.WriteLine("");
Console.WriteLine("5.View Everyday Banking Details");
Console.WriteLine("6.View Investment Banking Details");
Console.WriteLine("7.View Omni Banking details");
Console.WriteLine("");
Console.WriteLine("8.Exit");
}
// 主要
private static void Main(string[] args)
{
Client client = new Client("Tayla", "Brown", "027493922", "55 Grey Rd"); // Our one client
Everyday everyday = new Everyday(client, Account.GenerateAccountNumber(), 2000m);
Investment investment = new Investment(client, 500m);
Omni omni = new Omni(client, 1000m);
DisplayMenu();
string userchoice = Console.ReadLine();//user input from menu options
switch (userchoice.ToUpper())
{
case "1": // Display Client Info
Console.Clear();
Console.WriteLine(client.ClientInfo);
break;
case "2A": // Display Everday Account Balance
Console.Clear();
DisplayBalance(everyday);
break;
case "2B": // Display Investment Account Balance
Console.Clear();
DisplayBalance(investment);
break;
case "2C": // Display Omni Account Balance
Console.Clear();
DisplayBalance(omni);
break;
case "3A": // Everyday Account Deposit
DepositAmount(everyday);
break;
case "3B": // Investment Account Deposit
DepositAmount(investment);
break;
case "3C": // Omni Account Deposit
DepositAmount(omni);
break;
case "4A": // Everyday account Withdrawal
WithdrawAmount(everyday);
break;
case "4B": // Investment Account Withdrawal
WithdrawAmount(investment);
break;
case "4C": // Omni Account Withdrawal
WithdrawAmount(omni);
break;
case "5": // Everyday Details
DisplayDetails(everyday);
break;
case "6": // Investment Details
DisplayDetails(investment);
break;
case "7": // Omni Details
DisplayDetails(omni);
break;
case "8": // Exit Banking
Console.WriteLine("You have chosen to exit the online banking. Thanks and come again!");
break;
default: // catch all, breaks the loop
//Console.Clear()
break;
}
}
// 显示余额
private static void DisplayBalance(Account account)
{
Console.WriteLine($"{account.AccountType} Balance: {account.Balance:$#,##0.00}");
Console.ReadLine();
DisplayMenu();
}
string userchoice = Console.ReadLine();
及其下面的所有选项都需要包含在无限循环中,即 while (true) { ... }
。这使得一旦 switch
语句中断,系统将提示用户再次输入并继续循环。如果您不想使用 ctrl-C 终止,则必须将终止提示移到切换之前。例如:
while (true) { string userchoice = Console.ReadLine(); if (userchoice == 8) { Console.WriteLine("You have chosen to exit the online banking. Thanks"); break; } else { switch ...
编辑:无限循环代码
while (true) {
string userchoice = Console.ReadLine();//user input from menu options
switch (userchoice.ToUpper())
{
case "1": // Display Client Info
Console.Clear();
Console.WriteLine(client.ClientInfo);
break;
case "2A": // Display Everday Account Balance
Console.Clear();
DisplayBalance(everyday);
break;
case "2B": // Display Investment Account Balance
Console.Clear();
DisplayBalance(investment);
break;
case "2C": // Display Omni Account Balance
Console.Clear();
DisplayBalance(omni);
break;
case "3A": // Everyday Account Deposit
DepositAmount(everyday);
break;
case "3B": // Investment Account Deposit
DepositAmount(investment);
break;
case "3C": // Omni Account Deposit
DepositAmount(omni);
break;
case "4A": // Everyday account Withdrawal
WithdrawAmount(everyday);
break;
case "4B": // Investment Account Withdrawal
WithdrawAmount(investment);
break;
case "4C": // Omni Account Withdrawal
WithdrawAmount(omni);
break;
case "5": // Everyday Details
DisplayDetails(everyday);
break;
case "6": // Investment Details
DisplayDetails(investment);
break;
case "7": // Omni Details
DisplayDetails(omni);
break;
case "8": // Exit Banking
Console.WriteLine("You have chosen to exit the online banking. Thanks and come again!");
break;
default: // catch all, breaks the loop
//Console.Clear()
break;
}
}
嗨,我是新手,我正在尝试找出一种方法,让客户可以从 DisplayMenu 输入他们选择的选项,然后将他们带到另一个屏幕,如 DisplayBalance(),这是目前正在运行的。但随后我希望他们按下回车键,然后 return 他们回到 DisplayMenu() 并能够输入另一个选项将他们带到另一个屏幕,但目前正在发生的是控制台退出。有谁知道如何解决这个问题?
// 显示菜单
private static void DisplayMenu()
{
Console.WriteLine("Welcome to your online bank account\nPlease choose from the options below: ");
Console.WriteLine("");
Console.WriteLine("1.View Client Info");
Console.WriteLine("");
Console.WriteLine("2. View Account Balance:");
Console.WriteLine(" 2A.Everyday\n 2B.Investment\n 2C.Omni");
Console.WriteLine("");
Console.WriteLine("3.Deposit Funds:\n 3A.Everyday\n 3B.Investment\n 3C.Omni");
Console.WriteLine("");
Console.WriteLine("4.Withdraw Funds:\n 4A.Everyday\n 4B.Investment\n 4C.Omni");
Console.WriteLine("");
Console.WriteLine("5.View Everyday Banking Details");
Console.WriteLine("6.View Investment Banking Details");
Console.WriteLine("7.View Omni Banking details");
Console.WriteLine("");
Console.WriteLine("8.Exit");
}
// 主要
private static void Main(string[] args)
{
Client client = new Client("Tayla", "Brown", "027493922", "55 Grey Rd"); // Our one client
Everyday everyday = new Everyday(client, Account.GenerateAccountNumber(), 2000m);
Investment investment = new Investment(client, 500m);
Omni omni = new Omni(client, 1000m);
DisplayMenu();
string userchoice = Console.ReadLine();//user input from menu options
switch (userchoice.ToUpper())
{
case "1": // Display Client Info
Console.Clear();
Console.WriteLine(client.ClientInfo);
break;
case "2A": // Display Everday Account Balance
Console.Clear();
DisplayBalance(everyday);
break;
case "2B": // Display Investment Account Balance
Console.Clear();
DisplayBalance(investment);
break;
case "2C": // Display Omni Account Balance
Console.Clear();
DisplayBalance(omni);
break;
case "3A": // Everyday Account Deposit
DepositAmount(everyday);
break;
case "3B": // Investment Account Deposit
DepositAmount(investment);
break;
case "3C": // Omni Account Deposit
DepositAmount(omni);
break;
case "4A": // Everyday account Withdrawal
WithdrawAmount(everyday);
break;
case "4B": // Investment Account Withdrawal
WithdrawAmount(investment);
break;
case "4C": // Omni Account Withdrawal
WithdrawAmount(omni);
break;
case "5": // Everyday Details
DisplayDetails(everyday);
break;
case "6": // Investment Details
DisplayDetails(investment);
break;
case "7": // Omni Details
DisplayDetails(omni);
break;
case "8": // Exit Banking
Console.WriteLine("You have chosen to exit the online banking. Thanks and come again!");
break;
default: // catch all, breaks the loop
//Console.Clear()
break;
}
}
// 显示余额
private static void DisplayBalance(Account account)
{
Console.WriteLine($"{account.AccountType} Balance: {account.Balance:$#,##0.00}");
Console.ReadLine();
DisplayMenu();
}
string userchoice = Console.ReadLine();
及其下面的所有选项都需要包含在无限循环中,即 while (true) { ... }
。这使得一旦 switch
语句中断,系统将提示用户再次输入并继续循环。如果您不想使用 ctrl-C 终止,则必须将终止提示移到切换之前。例如:
while (true) { string userchoice = Console.ReadLine(); if (userchoice == 8) { Console.WriteLine("You have chosen to exit the online banking. Thanks"); break; } else { switch ...
编辑:无限循环代码
while (true) {
string userchoice = Console.ReadLine();//user input from menu options
switch (userchoice.ToUpper())
{
case "1": // Display Client Info
Console.Clear();
Console.WriteLine(client.ClientInfo);
break;
case "2A": // Display Everday Account Balance
Console.Clear();
DisplayBalance(everyday);
break;
case "2B": // Display Investment Account Balance
Console.Clear();
DisplayBalance(investment);
break;
case "2C": // Display Omni Account Balance
Console.Clear();
DisplayBalance(omni);
break;
case "3A": // Everyday Account Deposit
DepositAmount(everyday);
break;
case "3B": // Investment Account Deposit
DepositAmount(investment);
break;
case "3C": // Omni Account Deposit
DepositAmount(omni);
break;
case "4A": // Everyday account Withdrawal
WithdrawAmount(everyday);
break;
case "4B": // Investment Account Withdrawal
WithdrawAmount(investment);
break;
case "4C": // Omni Account Withdrawal
WithdrawAmount(omni);
break;
case "5": // Everyday Details
DisplayDetails(everyday);
break;
case "6": // Investment Details
DisplayDetails(investment);
break;
case "7": // Omni Details
DisplayDetails(omni);
break;
case "8": // Exit Banking
Console.WriteLine("You have chosen to exit the online banking. Thanks and come again!");
break;
default: // catch all, breaks the loop
//Console.Clear()
break;
}
}