In this C# example, we are performing the ATM Transaction. The types of ATM transaction are
1) Balance Checking, 2) Cash Withdrawal ,3) Cash Deposition, 4)Quit
We are reading the pin number using ‘pin’ variable. If condition statement is used to check the value of ‘pin’ variable is not equal to 1520. If the condition is true, then execute the statement.
Print the statement as please enter valid password.
Do-While statement is used to print the types of ATM transaction.
The ‘choice’ variable is used to select anyone types of transaction. Use the value of ‘choice’ variable in the switch case statement. Case1 is used to print the available balance from the value of ‘amount’ variable. To withdraw the amount case2 statement is used.
Read the amount to withdraw using ‘withdraw’ variable. Nested If-Else condition statement is used to check the modulus of the value of ‘withdraw’ variable by 100 is not equal to 0. If the condition is true then print the statement as “please enter the amount in multiples of 100”.
Otherwise, if the condition is false, then execute the else if condition statement. Check the difference between the values of ‘amount’ variable by 500 is less than the value of ‘withdraw’ variable. Once the condition is true then execute the statement and print the statement as insufficient balance.
Otherwise, if the condition is false, execute the else condition statement. Assign the difference between the values of ‘amount’ variable by the value of ‘withdraw’ variable. Print the statement as please collect cash and your current balance using the value of ‘amount’ variable value.
To deposit the amount case3 statement is used to get the amount to deposit using deposit variable and assigns the resulted value to amount variable. Compute the summation of the value of ‘amount’ variable with the value of ‘deposit’ variable. Print the statement as the balance using amount variable value.
C# Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApp11 { class Program { static void Main(string[] args) { int amount = 1000, deposit, withdraw; int choice, pin = 0, x = 0; Console.WriteLine("Enter Your Pin Number "); pin = int.Parse(Console.ReadLine()); while (true) { Console.WriteLine("********Welcome to ATM Service**************\n"); Console.WriteLine("1. Check Balance\n"); Console.WriteLine("2. Withdraw Cash\n"); Console.WriteLine("3. Deposit Cash\n"); Console.WriteLine("4. Quit\n"); Console.WriteLine("*********************************************\n\n"); Console.WriteLine("Enter your choice: "); choice = int.Parse(Console.ReadLine()); switch (choice) { case 1: Console.WriteLine("\n YOUR BALANCE IN Rs : {0} ", amount); break; case 2: Console.WriteLine("\n ENTER THE AMOUNT TO WITHDRAW: "); withdraw = int.Parse(Console.ReadLine()); if (withdraw % 100 != 0) { Console.WriteLine("\n PLEASE ENTER THE AMOUNT IN MULTIPLES OF 100"); } else if (withdraw > (amount - 500)) { Console.WriteLine("\n INSUFFICENT BALANCE"); } else { amount = amount - withdraw; Console.WriteLine("\n\n PLEASE COLLECT CASH"); Console.WriteLine("\n YOUR CURRENT BALANCE IS {0}", amount); } break; case 3: Console.WriteLine("\n ENTER THE AMOUNT TO DEPOSIT"); deposit = int.Parse(Console.ReadLine()); amount = amount + deposit; Console.WriteLine("YOUR BALANCE IS {0}", amount); break; case 4: Console.WriteLine("\n THANK U USING ATM"); break; } } Console.WriteLine("\n\n THANKS FOR USING OUT ATM SERVICE"); } } } |
The C# program is successfully compiled and executed with Microsoft Visual Studio. The program output is also shown below.