Skip to content

Instantly share code, notes, and snippets.

@grantwinney
Created August 3, 2018 21:08
Show Gist options
  • Save grantwinney/621cda695bf1095c97b72178d4e6afbc to your computer and use it in GitHub Desktop.
Save grantwinney/621cda695bf1095c97b72178d4e6afbc to your computer and use it in GitHub Desktop.
an example for a blog post - comments on what
public static void Main()
{
// get account details
var accountId = "1234";
var name = "Grant";
var balance = 100m;
var secretAnswer = "42";
// validate the user in secretive fashion
var answer = "";
while (answer != secretAnswer)
{
// get the user's input
Console.Write("Provide your secret answer before continuing: ");
answer = Console.ReadLine();
// if the secret is invalid, yell at them
if (answer != secretAnswer)
Console.WriteLine("\nWRONG!!!");
}
// determine the type of transaction
var action = "";
while (action != "D" && action != "W")
{
// get the user's action
Console.Write($"Hello {name}, [W]ithdrawal or [D]eposit? ");
action = Console.ReadLine();
// if the action is invalid, tell them and try again
if (action != "D" && action != "W")
Console.WriteLine("\nInvalid option!");
}
// determine the amount of the transaction
var amount = 0;
while (amount <= 0)
{
// get the user's amount
Console.Write($"How much is this transaction for? (You have ${balance}) ");
// if the amount is invalid, try again
if (!Int32.TryParse(Console.ReadLine(), out amount) || amount <= 0)
Console.WriteLine("\nInvalid amount!");
}
// inform user that the action was recorded
Console.WriteLine($"\nThanks {name}, we recorded your {(action == "D" ? "deposit" : "withdrawal")} of ${amount}.");
// inform user of the new account balance
Console.WriteLine($"For your records, you now have ${(balance + (action == "D" ? amount : -amount))} in your account.");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment