ATM Machine Transactions Program in C#

Learn, how to make a simple ATM based program with basic operations like check balance, withdraw money, deposit money, change PIN number etc?
Submitted by Ridhima Agarwal, on October 18, 2017 [Last updated : March 19, 2023]

In this solution, we will learn how an ATM functions? Just like our daily operations we are implementing the same features in this program, like: deposit cash, withdraw money, check balance, change PIN number etc.

Firstly, a predefined PIN is initialized in this program, so that it can be matched with the given (input) PIN number. And then we select the operations given in the program. Based on the selected operation program will work.

C# program to make a simple ATM machine transaction

using System;
namespace atm_program {
  class ab {
    static void Main(String[] args) {
      int amt = 10000, a, current, pin = 4040, pin1, pin2;

      //read PIN
      Console.WriteLine("Enter the pin");
      pin1 = int.Parse(Console.ReadLine());

      //compare PIN
      if (pin1 == pin) {
        Console.WriteLine("1.To check balance");
        Console.WriteLine("2.To withdraw money");
        Console.WriteLine("3.To deposite Money");
        Console.WriteLine("4.To change the pin");
        Console.WriteLine("Enter your choice");
        int ch = int.Parse(Console.ReadLine());
        switch (ch) {
        case 1:
          Console.WriteLine("The current balance in your account is" + amt);
          break;

        case 2:
          Console.WriteLine("Enter the amount to withdraw"); {
            a = int.Parse(Console.ReadLine());
            if (amt >= a) {
              if (a % 100 == 0) {
                Console.WriteLine("Please collect the cash" + a);
                current = amt - a;
                Console.WriteLine("The current balance is now" + current);
              } else
                Console.WriteLine("Please enter the amount to withdraw in the multiples of 100");
            } else
              Console.WriteLine("Your account does not have sufficient balance");
          }

          break;

        case 3:
          Console.WriteLine("Enter the amount to be deposite");
          a = int.Parse(Console.ReadLine());
          current = amt + a;
          Console.WriteLine("The current balance in the account is" + current);
          break;

        case 4:
          Console.WriteLine("Want to change your pin");
          Console.WriteLine("Enter your previous pin");
          int prepin = int.Parse(Console.ReadLine());
          if (prepin == pin) {
            Console.WriteLine("Enter your new pin");
            pin2 = int.Parse(Console.ReadLine());
            pin1 = pin2;
            Console.WriteLine("Your pin is changed");
          } else
            Console.WriteLine("Enter your correct pin");
          break;

        default:
          Console.WriteLine("Please select correct option");
          break;
        }
      } else
        Console.WriteLine("Pin is wrong");
    }
  }
}

Output

RUN 1:
Enter the pin
4040
1.To check balance
2.To withdraw money
3.To deposite Money
4.To change the pin
Enter your choice
3
Enter the amount to be deposite
10000
The current balance in the account is20000

RUN 2:
Enter the pin
4040
1.To check balance
2.To withdraw money
3.To deposite Money
4.To change the pin
Enter your choice
2
Enter the amount to withdraw
1000
Please collect the cash1000
The current balance is now9000

RUN 3:
Enter the pin
4040
1.To check balance
2.To withdraw money
3.To deposite Money
4.To change the pin
Enter your choice
1
The current balance in your account is10000

RUN 4:
Enter the pin
4040
1.To check balance
2.To withdraw money
3.To deposite Money
4.To change the pin
Enter your choice
4
Want to change your pin
Enter your previous pin
4040
Enter your new pin
1234
Your pin is changed

Output (Screenshots)

atm program in C# -1 atm program in C# -2

C# Basic Programs »

Comments and Discussions!

Load comments ↻





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