C# program to demonstrate ATM transactions

ATM transactions programs in C# with the operations like deposit, withdrawal, check account balance, etc.
Submitted by Nidhi, on August 17, 2020

Here we will create a C# program to demonstrate ATM transaction like deposit, withdrawal, check account balance.

Program:

The source code to demonstrate the ATM transaction in C# is given below. The given program is compiled and executed successfully on Microsoft Visual Studio.

//Program to demonstrate ATM transaction in C#.

using System;

class ATMDemo
{
    public static void Main()
    {
        int totalBalance    = 50000;
        int depositAmount   = 0; 
        int withdrawAmount  = 0;

        int option;
            
        int Atmpin = 0;
        
        Console.Write("Enter Your ATM Pin: ");
        Atmpin = int.Parse(Console.ReadLine());

        if (Atmpin == 1234)
        {
            Console.WriteLine("#########Select ATM Service##########\n");
            Console.WriteLine("1. Balance Enquiry\n");
            Console.WriteLine("2. Cash Withdrawal\n");
            Console.WriteLine("3. Deposit your Cash\n");
            Console.WriteLine("4. Exit\n");
            Console.WriteLine("#####################################\n\n");
            Console.Write("Select option: ");

            option = int.Parse(Console.ReadLine());

            switch (option)
            {
                case 1:
                    Console.Write("\nYour Total Account Balanace : "+totalBalance);
                    break;
                case 2:
                    Console.Write("\nEnter withdrawal amount: ");
                    withdrawAmount = int.Parse(Console.ReadLine());

                    if (withdrawAmount % 100 != 0)
                    {
                        Console.WriteLine("\nPlease enter withdrawal amount in multiple of 100");
                    }
                    else if (withdrawAmount > totalBalance)
                    {
                        Console.WriteLine("\nIn-sufficient balance in your account");
                    }
                    else
                    {
                        totalBalance = totalBalance - withdrawAmount;
                        Console.WriteLine("\n\nPlease collect your money");
                        Console.WriteLine("\nYour remaining balance is: "+totalBalance);
                    }
                    break;
                case 3:
                    Console.Write("\nEnter amount to deposit: ");
                    depositAmount = int.Parse(Console.ReadLine());
                    totalBalance = totalBalance + depositAmount;
                    Console.WriteLine("Your current balance: "+totalBalance);
                    break;
                case 4:
                    Console.WriteLine("\nInvalid Option");
                    break;
            }
        }
        else
        {
            Console.WriteLine("Invalid Pin Number");
        }
        Console.WriteLine("\n\nTHANKS FOR USING OUT ATM SERVICE");
    }
}

Output:

Enter Your ATM Pin: 1234
#########Select ATM Service##########

1. Balance Enquiry

2. Cash Withdrawal

3. Deposit your Cash

4. Exit

#####################################


Select option: 2

Enter withdrawal amount: 5000


Please collect your money

Your remaining balance is: 45000

THANKS FOR USING OUT ATM SERVICE
Press any key to continue . . .

Explanation:

In the above program, we created a class ATMDEMO that contains the Main() method. Here we created an ATM menu that provides the following options:

  1. Balance Enquiry
  2. Cash Withdrawal
  3. Deposit your Cash
  4. Exit

Here we take user input for ATM PIN, if ATM PIN is correct then we can use the above options.

Balance Enquiry:

Here we print the total balance of the user.

Cash Withdrawal:

Here we checked entered amount that should be multiple of 100, and check entered amount must be less than total balance, if both conditions are satisfied then we can withdraw the amount from ATM.

Deposit Cash:

Here we took amount as input and add to the total balance and then print total balance on the screen.

Exit:

This option is used to exit from ATM program.






Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.





Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates


© https://www.includehelp.com some rights reserved.