Im a complete beginner to C# and trying to make a project by learning class. But Im stuck with this problem. I'm trying to pass a variable from this class
class UserAccount
{
decimal balance = 0;
public void PrintBalance()
{
Console.WriteLine("\nYour balance is: {0}", balance);
}
}
to another class and want to use it in my if statement and possibly edit the variable balance
class UserInterface
{
public UserInterface()
{
UserAccount userAccount = new UserAccount();
Console.WriteLine("~~~Welcome to ATM Service~~~");
Console.WriteLine("\nPlease select from the following:\n");
Console.WriteLine("[1] Check Balance");
Console.WriteLine("[2] Withdraw Cash");
Console.WriteLine("[3] Deposit Cash");
Console.WriteLine("[4] Quit ATM Service");
Console.WriteLine("");
int userChoice = Convert.ToInt32(Console.ReadLine());
switch (userChoice)
{
case 1:
userAccount.PrintBalance();
break;
case 2:
Console.WriteLine("Enter amount you wish to withdraw.");
int withdrawAmount = Convert.ToInt32(Console.ReadLine());
if(withdrawAmount <= 0)
{
Console.WriteLine("Amount must not be negative number or 0.");
break;
}
if(withdrawAmount < userAccount.balance)
{
}
I'm stuck with userAccount.balance in the if statement. Any help would be greatly appreciated.