For a school assignment I'm supposed to create a menu kind of like an ATM.
My professor gave us this code to use:
string choice = null;
do
{
Console.Write("[O]pen Account [I]nquire [D]eposit [W]ithdraw [Q]uit: ");
choice = Console.ReadLine();
choice = choice.ToUpper();
switch (choice)
{
case "O": // open an account
case "I": // inquire
case "D": // deposit
case "W": // withdraw
default: break;
}
} while (choice != "Q");
Here is what I did:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
string choice = null;
string CustomerName;
Console.WriteLine("Welcome to Fantasy Bank");
Console.Write("Please enter your name:");
CustomerName = Console.ReadLine();
do
{
Console.WriteLine("What can I do for you");
Console.Write("[O]pen Account [I]nquire [D]eposit [W]ithdraw [Q]uit: ");
choice = Console.ReadLine();
choice = choice.ToUpper();
double CurrentBalance = 0;
switch (choice)
{
case "O": // open an account
Console.Write("Name of account holder:");
Console.WriteLine(CustomerName);
Console.Write("Initial Deposit:");
CurrentBalance = Convert.ToDouble(Console.ReadLine()); // i get a major error if someone types in a letter instead of a number
Console.Write("You have succesfully opened an account with an initial deposit of ");
Console.Write(CurrentBalance);
Console.WriteLine(" at an imaginary bank. Congratulations");
break;
case "I": // inquire
Console.Write(CustomerName);
Console.WriteLine("'s Bank Account");
Console.WriteLine(CurrentBalance);
break;
I did a little bit more, but the problem starts here in case "I". CustomerName is getting replaced by what the user types, like it's supposed to be. But CurrentBalance does not change, and I have to set it equal to something otherwise I get an error.
I start to get the feeling that it may be impossible to change a switch variable inside a switch. I looked in my book for passing references/values, but it doesn't include switch in that section.
If y'all could give me a hint what I'm doing wrong or could show me what could fix my problem, that would be great. I'm not expecting code from you, just a little push in the right direction.