Creating an ATM machine in C++ is a practical way to strengthen your programming fundamentals. By implementing core features like depositing, withdrawing, and checking the balance. Such projects are excellent for hands-on learning and improving logical thinking.

Let’s see how this simulation looks & works:
What is the pre-requisite things you need?
If you know the basics of C++ such as loops, switch cases, and variables then you’re good to go. If you don’t know then learn it easily: Link
Understanding the Code Structure
The ATM simulation consists of a single main function and a custom function to handle the transactions (atm_operations). The main logic is built using a switch-case structure that processes the user’s input and allows them to choose different ATM operations.
Key Components of the Program:
Global Variables:
- current_balance: This stores the user’s current balance, initialized to 0.0, simulating a new user with no funds.
- follow_up_choice: This variable controls whether the user wishes to continue with a new transaction after completing one.
- Function Definition:
The atm_operations() function has the ATM’s core logic. Inside this function, the user is prompted with different ATM options and can interact with the system accordingly.
Based on the selected option (deposit, withdraw, or check balance), the function will execute the corresponding block of code.
Transaction Options:
- Deposit Money: The user can enter an amount to deposit. The balance is updated, and the user is prompted to continue.
- Withdraw Money: The user can withdraw money from the ATM. The program checks if the withdrawal amount exceeds the available balance and provides appropriate feedback.
- Check Balance: The user can check their current bank balance anytime.
How the Program Works?
User Interaction:
The program begins by displaying three options to the user: deposit money, withdraw money, and check balance. The user is prompted to input a number corresponding to their desired transaction.
Transaction Execution:
- When the user chooses to deposit money, they’ll be asked to enter the amount to deposit, and that amount will then be added to their balance.
- To withdraw money, the program first checks if the requested amount is greater than the available balance. If so, it alerts the user of insufficient funds. Otherwise, it updates the balance accordingly.
- If the user selects to check the balance, the current balance is displayed.
- Continuation or Exit: After each transaction, the user is asked if they want to perform another operation. If they choose to continue, the program calls the atm_operations function recursively to restart the process. If they choose to exit, the program terminates with a thank you message.
Recursion for Repeated Operations:
The recursion in the program allows users to perform multiple transactions one after the other without restarting the program. This makes the simulation of the atm machine code in C++ more user-friendly.
The Complete Simple ATM Machine Program in C++ Code:
Directly copy & paste the ATM Machine in c++ code into the compiler:
#include <iostream> using namespace std; int follow_up_choice; // Keeps track of whether the user wants to continue with another transaction float current_balance = 0.0; // Initial balance set to 0.0 void atm_operations() { // Display ATM options to the user cout << "ATM Options Available" << endl; cout << "1. Add Money" << endl; cout << "2. Take Money Out" << endl; cout << "3. Check Balance" << endl; cout << "\n"; // User input for selecting the desired transaction int selected_option; cout << "Please choose an option: "; cin >> selected_option; float withdraw_amount, deposit_amount; // Switch case for handling user input switch(selected_option) { case 1: // Case for adding money to the account cout << "\nEnter the amount to deposit: "; cin >> deposit_amount; current_balance += deposit_amount; // Add the deposit to the current balance cout << "Your updated balance is Rs. " << current_balance << ". Thank you for adding money!" << endl; cout << "Do you wish to perform another action?\nPress 1 to 'continue' or 2 to 'exit'." << endl; cout << "Your choice: "; cin >> follow_up_choice; if (follow_up_choice == 1){ atm_operations(); // Call the function recursively to continue the process } break; case 2: // Case for withdrawing money cout << "\nEnter amount to withdraw: "; cin >> withdraw_amount; // Check if the withdrawal amount exceeds the balance if (withdraw_amount > current_balance) { cout << "Insufficient balance! Please add funds first." << endl; cout << "Do you wish to perform another action?\nPress 1 to 'continue' or 2 to 'exit'." << endl; cout << "Your choice: "; cin >> follow_up_choice; if (follow_up_choice == 1){ atm_operations(); // Recursively call for another transaction } } else { current_balance -= withdraw_amount; // Subtract the withdrawal amount from the balance cout << "You have successfully withdrawn Rs. " << withdraw_amount << ". Your new balance is Rs. " << current_balance << endl; cout << "Do you wish to perform another action?\nPress 1 to 'continue' or 2 to 'exit'." << endl; cout << "Your choice: "; cin >> follow_up_choice; if (follow_up_choice == 1){ atm_operations(); // Continue if the user chooses to perform another action } } break; case 3: // Case for checking the current balance cout << "Your current balance is: Rs. " << current_balance << endl; cout << "Do you wish to perform another action?\nPress 1 to 'continue' or 2 to 'exit'." << endl; cout << "Your choice: "; cin >> follow_up_choice; // Continue if the user wants to perform another action if (follow_up_choice == 1){ atm_operations(); } break; default: cout << "Invalid choice, please try again!" << endl; // Handle invalid input and prompt the user to try again atm_operations(); break; } } int main() { atm_operations(); // Start the ATM operations // Closing message cout << "Thank you for using the ATM. Have a great day!" << endl; return 0; }
Conclusion
In conclusion, building an ATM machine in C++ is an excellent way to enhance your programming skills and understand core concepts like conditionals, loops, and functions. By implementing features such as balance checking, cash withdrawal, and deposit functionalities, you gain practical experience in creating user-friendly and functional applications.
If you found this tutorial helpful, don’t forget to check out more programming guides and resources on CodeHelping. Keep coding, keep learning, and happy programming!
For coding projects of JavaScript, C++, and Python along with their source code visit Link