Reputation: 133
I am new to programming, RightNow I am following some online tutorials (from Microsoft). This is my code, so far I hardcoded values like cash to deposit or cash to withdraw, my question is very simple how to take input from the user.
var savings = new SavingAccount("Saving Account", 10000);
savings.MakeDeposite(1000, DateTime.Now, "Saving from Laptop");
savings.MakeDeposite(525, DateTime.Now, "Saving from Hard-drive");
savings.MakeWithdrawal(2500, DateTime.Now, "Needed for buying goods");
savings.PerformMonthEndTransactions();
Console.WriteLine(savings.GetAccountHistory());
var currents = new CurrentAccount("Current Account", 0, 1000);
currents.MakeDeposite(150000, DateTime.Now, "Salary Transfered");
currents.MakeWithdrawal(25000, DateTime.Now, "Pay bills");
currents.MakeWithdrawal(50000, DateTime.Now, "Rent");
currents.PerformMonthEndTransactions();
Console.WriteLine(currents.GetAccountHistory());
do I need to do some changes in the constructor as well? this is my constructor
public BankAccount(string name, decimal initialBalance) : this(name, initialBalance, 0) { }
public BankAccount(string name, decimal initialBalance, decimal minimumBalance)
{
//this.Owner = name;
//this.Balance = initialBalance;
this.Number = accountNumberSeed.ToString();
accountNumberSeed++;
this.Owner = name;
this.minimumBalance = minimumBalance;
if(initialBalance > 0)
MakeDeposite(initialBalance, DateTime.Now, "Initial Balance");
}
Upvotes: 0
Views: 69
Reputation: 46
Per @Johnny Mopp, you can use Console.ReadLine()
to get the input from user.
For example:
static void Main(string[] args)
{
Console.Write("Specify your amount: ");
if (decimal.TryParse(Console.ReadLine(), out decimal amount))
Console.WriteLine("amount entered: " + amount);
else
Console.WriteLine("Conversion of user input to decimal failed.");
}
Upvotes: 3