ATM Simulation Program in C, C++, Java & Python – Code with Explanation & Examples in Short and Simple

   

C Program

#include <stdio.h>
int main() {
    int c; float b = 1000, a;
    scanf("%d %f", &c, &a);
    switch(c) {
        case 1: printf("Balance: %.2f", b); break;
        case 2: printf(b >= a ? "Withdrawn: %.2f" : "Insufficient", a); break;
        case 3: printf("Deposited: %.2f", b + a); break;
        default: printf("Invalid");
    }
}

C Output

Input:
2 300

Output:
Withdrawn: 300.00



C++ Program

#include <iostream>
using namespace std;
int main() {
    int c; float a, b = 1500;
    cin >> c >> a;
    switch(c) {
        case 1: cout << "Balance: " << b; break;
        case 2: cout << (a <= b ? "Withdrawn: " + to_string(a) : "Insufficient"); break;
        case 3: cout << "Deposited: " << b + a; break;
        default: cout << "Invalid";
    }
}

C++ Output

Input:
3 500

Output:
Deposited: 2000



JAVA Program

import java.util.*;
public class Main {
    public static void main(String[] a) {
        Scanner s = new Scanner(System.in);
        int c = s.nextInt(); float b = 800, amt = s.nextFloat();
        switch (c) {
            case 1: System.out.println("Balance: " + b); break;
            case 2: System.out.println(amt <= b ? "Withdrawn: " + amt : "Insufficient"); break;
            case 3: System.out.println("Deposited: " + (b + amt)); break;
            default: System.out.println("Invalid");
        }
    }
}

JAVA Output

Input:
1 0

Output:
Balance: 800.0



Python Program

c, a = map(float, input().split()); b = 900
if c == 1: print("Balance:", b)
elif c == 2: print("Withdrawn:" if a <= b else "Insufficient", a)
elif c == 3: print("Deposited:", b + a)
else: print("Invalid")

Python Output

Input:
2 950

Output:
Insufficient 950.0



In-Depth Explanation
Example
Let’s say a user chooses option 2 (Withdraw) and inputs amount 300. If the balance is 1000, the program checks if 300 <= 1000. Since it is, the output is Withdrawn: 300.00. Otherwise, the message is Insufficient.

This is the core logic of ATM systems: verify and execute based on the user's choice.

Real-Life Analogy
Imagine going to an ATM machine. It shows a menu:

Check Balance

Withdraw Money

Deposit Money

You type a number to represent your action and type in the amount if necessary. That's all this program mimics—without the card or PIN for ease of use.

Why It Matters
ATM simulation teaches condition logic with respect to user input—namely using switch-case. It introduces menu-programming, one of the most prevalent real-world formats. Recognizing how operations are based on user decision-making is crucial in constructing systems that deal with humans or react to commands.

Learning Insights
This exercise teaches:

Menu-driven implementation (such as options 1/2/3)

Use of switch and if-else efficiently

Dealing with balance-based logic

Guarding against overdrafts

Modular approach (each case does one thing)

It also reinforces numeric input processing and arithmetic operations. Students also get to notice a single line of logic that emulates actual operations such as withdrawal checks, deposits, and printing balances.

Interview and Project Use
This is a familiar question in initial-stage interviews and projects. It tests:

Your knowledge of conditional statements

Menu construction

Implementation of real-world logic

In actual usage, this includes:

ATM backends

Banking apps

Wallet systems (such as Paytm, PhonePe)

Financial simulations

An ATM simulation program is the most effective method to learn decision logic and menu-driven program design. It provides real-life financial situations and a lesson in clean input/output flow. With the most concise working code in C, C++, Java, and Python, this tutorial provides a solid introduction to decision-making, user interaction, and program control. Perfect for new programmers, coding interviews, and educational projects, this program translates real-world programming experience into an easy-to-understand format.