Untitled
unknown
plain_text
8 days ago
1.8 kB
2
Indexable
Never
using System; public class prog { public void CheckBalance(double atmBalance, double cashBalance) { Console.WriteLine("Current cash on hand: " + atmBalance); Console.WriteLine("Current atm balance: " + cashBalance); } public void WithdrawCash(ref double atmBalance, ref double cashBalance) { Console.Write("Enter withdrawal amount: "); double withdrawalAmount = double.Parse(Console.ReadLine()); if (withdrawalAmount > atmBalance) { Console.WriteLine("Insufficient Balance"); } else { atmBalance = atmBalance - withdrawalAmount; cashBalance = cashBalance + withdrawalAmount; Console.WriteLine($"Successfully withdrew {withdrawalAmount}"); } } public void DepositCash(ref double atmBalance, ref double cashBalance) { Console.Write("Enter deposit amount: "); double depositAmount = double.Parse(Console.ReadLine()); if (depositAmount > cashBalance) { Console.WriteLine("Insufficient cash on hand"); } else { atmBalance = atmBalance + depositAmount; cashBalance = cashBalance - depositAmount; Console.WriteLine($"Successfully deposited {depositAmount}"); } } public static void Main(string[] args) { prog atm = new prog(); double atmBalance = 10000; double cashBalance = 10000; atm.CheckBalance(atmBalance, cashBalance); atm.WithdrawCash(ref atmBalance, ref cashBalance); atm.CheckBalance(atmBalance, cashBalance); atm.DepositCash(ref atmBalance, ref cashBalance); atm.CheckBalance(atmBalance, cashBalance); } }
Leave a Comment