ATM Transactions Program in C#

ATM transactions programs in C# with the operations like deposit, withdrawal, check account balance, etc.
Submitted by Nidhi, on August 17, 2020 [Last updated : March 22, 2023]

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

C# program to ATM machine transactions

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.

C# Basic Programs »

Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.