C# Program to Display the ATM Transaction

This is a C# Program to display the atm transaction.

Problem Description

This C# Program Displays the ATM Transaction.

Problem Solution

Here The types of ATM transaction are
1) Balance checking
2) Cash withdrawal
3) Cash deposition.
You can opt any of the above transaction according to your need of transaction.

Program/Source Code

Here is source code of the C# Program to Display the ATM Transaction. The C# program is successfully compiled and executed with Microsoft Visual Studio. The program output is also shown below.

/*
 * C# Program to Display the ATM Transaction
 */
using System;
class program
{
    public static void Main()
    {
 
        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");
    }
 }
Program Explanation

In this C# program, we are performing the ATM Transaction. The types of ATM transaction are 1) Balance Checking, 2) Cash Withdrawal,3) Cash Deposition.

advertisement
advertisement

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”.

Note: Join free Sanfoundry classes at Telegram or Youtube

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.

advertisement
Runtime Test Cases
 
Enter Your Pin Number
123
********Welcome to ATM Service**************
 
1. Check Balance
 
2. Withdraw Cash
 
3. Deposit Cash
 
4. Quit
 
*********************************************
Enter your choice:
1
 YOUR BALANCE IN Rs : 1000

Sanfoundry Global Education & Learning Series – 1000 C# Programs.

If you wish to look at all C# Programming examples, go to 1000 C# Programs.

advertisement
If you find any mistake above, kindly email to [email protected]

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.