Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace MessAroundConsole
- {
- /// <summary>
- /// Program designed to emulate a simple bank account system
- /// </summary>
- class Program
- {
- /// <summary>
- /// Our Main section where our program starts and keeps returning to
- /// until the user choses to exit.
- /// </summary>
- /// <param name="args"></param>
- static void Main(string[] args)
- {
- PrintMenu(); // Looks for the function called PrintMenu which is below and runs it
- Console.WriteLine();
- Console.Write("HOW MUCH MONEY WOULD YOU LIKE IN YOUR BANK: ");
- int yourBalance = Int32.Parse(Console.ReadLine()); // Sets our starting balance
- // Here we start our program loop so that it keeps running as it will always
- // return true. Below we give an option for the user to choose which breaks
- // out of the loop
- while (true)
- {
- Console.WriteLine();
- Console.WriteLine("CHECK BALANCE (1)");
- Console.WriteLine("WITHDRAW MONEY (2)");
- Console.WriteLine("DEPOSIT MONEY (3)");
- Console.WriteLine("EXIT (4)");
- Console.WriteLine();
- Console.Write("WHAT WOULD YOU LIKE TO DO (1, 2, 3 or 4): ");
- int yourChoice = Int32.Parse(Console.ReadLine());
- if (yourChoice == 1)
- {
- CheckBalance(yourBalance); // This sends our balance which was declared
- // above to a function called CheckBalance that
- // is written below
- }
- if (yourChoice == 2)
- {
- yourBalance = Withdraw(yourBalance); // This is slightly different to the one
- // above as this one sends our balance to
- // the function called Withdraw that is written below. The function will then
- // return a number which yourbalance will then equal that returned number.
- // For example yourBalance may be 10 and is then sent to Withdraw which will
- // run a calculation of yourBalance - 5 = 5. So it will send the number 5
- // back. so yourBalance would now = 5
- }
- if (yourChoice == 3)
- {
- yourBalance = Deposit(yourBalance); // Does the same thing as documented for
- // withdraw excepts sends it to a different
- // function / method
- }
- if (yourChoice == 4)
- {
- break; // Ends the program
- }
- else
- {
- continue; // If any other number is selected it restarts
- }
- }
- }
- /// <summary>
- /// Prints a welcome screen. This is only called at the start of the program.
- /// </summary>
- static void PrintMenu()
- {
- Console.WriteLine("##########################################################");
- Console.WriteLine("##########################################################");
- Console.WriteLine("####### #######");
- Console.WriteLine("####### WELCOME #######");
- Console.WriteLine("####### #######");
- Console.WriteLine("##########################################################");
- Console.WriteLine("##########################################################");
- }
- /// <summary>
- /// This function / method is used to print out the users ballance.
- /// It takes what ever int paramater is sent to it (in this case the balance)
- /// and prints that on screen.
- /// </summary>
- /// <param name="balance"></param>
- static void CheckBalance(int balance)
- {
- Console.WriteLine();
- Console.WriteLine("YOUR BALANCE IS {0}",balance);
- }
- /// <summary>
- /// This function / method takes the int paramater that is sent to it
- /// (in this case the balance), asks how much the user would like to withdraw
- /// and then deducts that number from the balance. It then returns the new value
- /// which is updated in the Main program.
- /// This also checks that the user isnt trying to withdraw more than is available.
- /// </summary>
- /// <param name="balance"></param>
- /// <returns></returns>
- static int Withdraw(int balance)
- {
- Console.WriteLine();
- Console.Write("HOW MUCH DO YOU WISH TO WITHDRAW: ");
- int withdrawAmnt = Int32.Parse(Console.ReadLine());
- if (withdrawAmnt > balance)
- {
- Console.WriteLine();
- Console.WriteLine("YOU HAVE INSUFICIENT FUNDS");
- }
- else
- {
- int resultingBalance = balance - withdrawAmnt;
- Console.WriteLine("WITHDRAW COMPLETE");
- return resultingBalance;
- }
- return balance;
- }
- /// <summary>
- /// This function / method takes the paramater sent to it from the Main program
- /// (in this case the balance) and asks how much the user would like to
- /// deposit. It then adds that to the balance and returns the new figure which
- /// is updated in the Main program.
- /// </summary>
- /// <param name="balance"></param>
- /// <returns></returns>
- static int Deposit(int balance)
- {
- Console.WriteLine();
- Console.Write("HOW MUCH DO YOU WISH TO DEPOSIT: ");
- int depositAmnt = Int32.Parse(Console.ReadLine());
- int resultingBalance = balance + depositAmnt;
- Console.WriteLine("DEPOSIT COMPLETE");
- return resultingBalance;
- }
- }
- }
Add Comment
Please, Sign In to add comment