Dosk3n

Bank Emulator

Mar 9th, 2014
242
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 6.42 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace MessAroundConsole
  8. {
  9.     /// <summary>
  10.     /// Program designed to emulate a simple bank account system
  11.     /// </summary>
  12.     class Program
  13.     {
  14.         /// <summary>
  15.         /// Our Main section where our program starts and keeps returning to
  16.         /// until the user choses to exit.
  17.         /// </summary>
  18.         /// <param name="args"></param>
  19.         static void Main(string[] args)
  20.         {
  21.             PrintMenu(); // Looks for the function called PrintMenu which is below and runs it
  22.             Console.WriteLine();
  23.             Console.Write("HOW MUCH MONEY WOULD YOU LIKE IN YOUR BANK: ");
  24.             int yourBalance = Int32.Parse(Console.ReadLine()); // Sets our starting balance
  25.            
  26.             // Here we start our program loop so that it keeps running as it will always
  27.             // return true. Below we give an option for the user to choose which breaks
  28.             // out of the loop
  29.             while (true)
  30.             {
  31.                 Console.WriteLine();
  32.                 Console.WriteLine("CHECK BALANCE (1)");
  33.                 Console.WriteLine("WITHDRAW MONEY (2)");
  34.                 Console.WriteLine("DEPOSIT MONEY (3)");
  35.                 Console.WriteLine("EXIT (4)");
  36.                 Console.WriteLine();
  37.                 Console.Write("WHAT WOULD YOU LIKE TO DO (1, 2, 3 or 4): ");
  38.                 int yourChoice = Int32.Parse(Console.ReadLine());
  39.  
  40.                 if (yourChoice == 1)
  41.                 {
  42.                     CheckBalance(yourBalance); // This sends our balance which was declared
  43.                                                // above to a function called CheckBalance that
  44.                                                // is written below
  45.                 }
  46.  
  47.                 if (yourChoice == 2)
  48.                 {
  49.                     yourBalance = Withdraw(yourBalance); // This is slightly different to the one
  50.                                                         // above as this one sends our balance to
  51.                     // the function called Withdraw that is written below. The function will then
  52.                     // return a number which yourbalance will then equal that returned number.
  53.                     // For example yourBalance may be 10 and is then sent to Withdraw which will
  54.                     // run a calculation of yourBalance - 5 = 5. So it will send the number 5
  55.                     // back. so yourBalance would now = 5
  56.                 }
  57.  
  58.                 if (yourChoice == 3)
  59.                 {
  60.                     yourBalance = Deposit(yourBalance); // Does the same thing as documented for
  61.                                                        // withdraw excepts sends it to a different
  62.                                                        // function / method
  63.                 }
  64.  
  65.                 if (yourChoice == 4)
  66.                 {
  67.                     break; // Ends the program
  68.                 }
  69.  
  70.                 else
  71.                 {
  72.                     continue; // If any other number is selected it restarts
  73.                 }
  74.  
  75.             }
  76.  
  77.         }
  78.  
  79.  
  80.         /// <summary>
  81.         /// Prints a welcome screen. This is only called at the start of the program.
  82.         /// </summary>
  83.         static void PrintMenu()
  84.         {
  85.             Console.WriteLine("##########################################################");
  86.             Console.WriteLine("##########################################################");
  87.             Console.WriteLine("#######                                            #######");
  88.             Console.WriteLine("#######                    WELCOME                 #######");
  89.             Console.WriteLine("#######                                            #######");
  90.             Console.WriteLine("##########################################################");
  91.             Console.WriteLine("##########################################################");
  92.         }
  93.        
  94.         /// <summary>
  95.         /// This function / method is used to print out the users ballance.
  96.         /// It takes what ever int paramater is sent to it (in this case the balance)
  97.         /// and prints that on screen.
  98.         /// </summary>
  99.         /// <param name="balance"></param>
  100.         static void CheckBalance(int balance)
  101.         {
  102.             Console.WriteLine();
  103.             Console.WriteLine("YOUR BALANCE IS {0}",balance);
  104.         }
  105.  
  106.         /// <summary>
  107.         /// This function / method takes the int paramater that is sent to it
  108.         /// (in this case the balance), asks how much the user would like to withdraw
  109.         /// and then deducts that number from the balance. It then returns the new value
  110.         /// which is updated in the Main program.
  111.         /// This also checks that the user isnt trying to withdraw more than is available.
  112.         /// </summary>
  113.         /// <param name="balance"></param>
  114.         /// <returns></returns>
  115.         static int Withdraw(int balance)
  116.         {
  117.             Console.WriteLine();
  118.             Console.Write("HOW MUCH DO YOU WISH TO WITHDRAW: ");
  119.             int withdrawAmnt = Int32.Parse(Console.ReadLine());
  120.             if (withdrawAmnt > balance)
  121.             {
  122.                 Console.WriteLine();
  123.                 Console.WriteLine("YOU HAVE INSUFICIENT FUNDS");
  124.             }
  125.             else
  126.             {
  127.                 int resultingBalance = balance - withdrawAmnt;
  128.                 Console.WriteLine("WITHDRAW COMPLETE");
  129.                 return resultingBalance;
  130.             }
  131.             return balance;
  132.         }
  133.  
  134.         /// <summary>
  135.         /// This function / method takes the paramater sent to it from the Main program
  136.         /// (in this case the balance) and asks how much the user would like to
  137.         /// deposit. It then adds that to the balance and returns the new figure which
  138.         /// is updated in the Main program.
  139.         /// </summary>
  140.         /// <param name="balance"></param>
  141.         /// <returns></returns>
  142.         static int Deposit(int balance)
  143.         {
  144.             Console.WriteLine();
  145.             Console.Write("HOW MUCH DO YOU WISH TO DEPOSIT: ");
  146.             int depositAmnt = Int32.Parse(Console.ReadLine());
  147.             int resultingBalance = balance + depositAmnt;
  148.             Console.WriteLine("DEPOSIT COMPLETE");
  149.             return resultingBalance;
  150.         }
  151.  
  152.  
  153.  
  154.     }
  155. }
Add Comment
Please, Sign In to add comment