0% found this document useful (0 votes)
31 views12 pages

C Code for ATM Transaction Simulator

The ATM Transaction Simulator project aims to simulate basic ATM operations like balance inquiry, deposit, withdrawal, fund transfer, and PIN change using C programming. It includes user authentication, transaction logging, and input validation, providing an interactive learning experience for beginners. Future enhancements may include multiple user accounts, file storage for account details, and a GUI version.

Uploaded by

itsjayasuriya07
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
31 views12 pages

C Code for ATM Transaction Simulator

The ATM Transaction Simulator project aims to simulate basic ATM operations like balance inquiry, deposit, withdrawal, fund transfer, and PIN change using C programming. It includes user authentication, transaction logging, and input validation, providing an interactive learning experience for beginners. Future enhancements may include multiple user accounts, file storage for account details, and a GUI version.

Uploaded by

itsjayasuriya07
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

ATM Transaction Simulator — Mini Project Report

1. Title of the Project

ATM Transaction Simulator

2. Objective

The main objective of this project is to simulate basic operations of an Automated Teller
Machine (ATM) such as balance inquiry, deposit, withdrawal, fund transfer, and PIN
change using the C programming language. This project helps to understand modular
programming, use of structures, arrays, functions, and basic I/O operations.

3. Problem Statement

Design and implement a console-based ATM simulator that authenticates a user using a
PIN and allows them to perform transactions like checking balance, withdrawing money,
depositing money, transferring funds, viewing a mini-statement, and changing the PIN.
The system must validate inputs and maintain an in-memory transaction log.

4. Tools Used

Programming Language: C
Compiler: GCC (GNU Compiler Collection)
Platform: Windows / Linux Console
Editor: VS Code / Code::Blocks / Dev C++

5. Algorithm / Flow of Execution

1. Start the program.


2. Initialize account with a default balance and PIN.
3. Authenticate the user by verifying the entered PIN (maximum 3 attempts).
4. Display the main menu with options: Check Balance, Deposit, Withdraw, Transfer,
Mini Statement, Change PIN, Exit.
5. Perform the selected operation and update balance/transaction log.
6. Display confirmation for the transaction.
7. Loop until the user chooses 'Exit'.
8. End the program.

6. Program Implementation (C Code)

The full C source code is included below. Copy this into a file named `atm_simulator.c`,
compile using `gcc atm_simulator.c -o atm_simulator` and run `./atm_simulator`.

--- C Source Code ---

/* atm_simulator.c

ATM Transaction Simulator - Mini Project

Compile: gcc atm_simulator.c -o atm_simulator

Run: ./atm_simulator

*/

#include <stdio.h>

#include <string.h>

#include <time.h>

#include <stdlib.h>

#define MAX_TXNS 20

#define PIN_TRIES_LIMIT 3

typedef struct {

char type[16]; // "Deposit", "Withdraw", "Transfer", "PIN


Change"

double amount;

char datetime[32]; // timestamp string

char note[64]; // optional description


} Transaction;

typedef struct {

double balance;

int pin;

Transaction txns[MAX_TXNS];

int tx_count;

} Account;

/* Utility: get current datetime string */

void now_str(char *buffer, size_t buflen) {

time_t t = time(NULL);

struct tm *tm_info = localtime(&t);

strftime(buffer, buflen, "%Y-%m-%d %H:%M:%S", tm_info);

/* Add transaction to account log (circular buffer behaviour) */

void add_transaction(Account *acc, const char *type, double amount,


const char *note) {

Transaction t;

strncpy([Link], type, sizeof([Link])-1);

[Link][sizeof([Link])-1] = '\0';

[Link] = amount;

now_str([Link], sizeof([Link]));

if (note) {

strncpy([Link], note, sizeof([Link])-1);

[Link][sizeof([Link])-1] = '\0';

} else {
[Link][0] = '\0';

if (acc->tx_count < MAX_TXNS) {

acc->txns[acc->tx_count++] = t;

} else {

// shift left and append to end

for (int i = 1; i < MAX_TXNS; ++i) acc->txns[i-1] = acc-


>txns[i];

acc->txns[MAX_TXNS-1] = t;

/* Display mini-statement */

void show_mini_statement(const Account *acc) {

printf("\n----- Mini Statement (last %d transactions) -----\n", acc-


>tx_count);

if (acc->tx_count == 0) {

printf("No transactions yet.\n");

} else {

for (int i = 0; i < acc->tx_count; ++i) {

const Transaction *t = &acc->txns[i];

printf("%2d) %s | %8.2f | %s", i+1, t->type, t->amount, t-


>datetime);

if (strlen(t->note) > 0) printf(" | %s", t->note);

printf("\n");

printf("-----------------------------------------------\n");
}

/* Authenticate PIN with up to PIN_TRIES_LIMIT tries */

int authenticate_pin(Account *acc) {

int tries = 0, input;

while (tries < PIN_TRIES_LIMIT) {

printf("Enter 4-digit PIN: ");

if (scanf("%d", &input) != 1) {

// clear input

while (getchar() != '\\n');

printf("Invalid input. Try again.\n");

continue;

if (input == acc->pin) {

printf("PIN accepted.\n");

return 1;

} else {

tries++;

printf("Incorrect PIN (%d/%d).\n", tries, PIN_TRIES_LIMIT);

printf("Maximum PIN attempts exceeded. Exiting.\n");

return 0;

void check_balance(const Account *acc) {

printf("\\nCurrent Balance: %.2f\\n\\n", acc->balance);

}
void deposit(Account *acc) {

double amt;

printf("Enter amount to deposit: ");

if (scanf("%lf", &amt) != 1 || amt <= 0) {

while (getchar() != '\\n');

printf("Invalid amount.\\n");

return;

acc->balance += amt;

add_transaction(acc, "Deposit", amt, "Cash deposit");

printf("Deposited %.2f successfully. New balance: %.2f\\n", amt,


acc->balance);

void withdraw(Account *acc) {

double amt;

printf("Enter amount to withdraw: ");

if (scanf("%lf", &amt) != 1 || amt <= 0) {

while (getchar() != '\\n');

printf("Invalid amount.\\n");

return;

if (amt > acc->balance) {

printf("Insufficient funds. Current balance: %.2f\\n", acc-


>balance);

return;

acc->balance -= amt;
add_transaction(acc, "Withdraw", amt, "Cash withdrawal");

printf("Withdrawn %.2f successfully. New balance: %.2f\\n", amt,


acc->balance);

void transfer(Account *acc) {

double amt;

char receiver[64];

printf("Enter receiver account (simulated, e.g., 12345678): ");

scanf("%s", receiver);

printf("Enter amount to transfer: ");

if (scanf("%lf", &amt) != 1 || amt <= 0) {

while (getchar() != '\\n');

printf("Invalid amount.\\n");

return;

if (amt > acc->balance) {

printf("Insufficient funds. Current balance: %.2f\\n", acc-


>balance);

return;

acc->balance -= amt;

char note[80];

snprintf(note, sizeof(note), "To %s", receiver);

add_transaction(acc, "Transfer", amt, note);

printf("Transferred %.2f to %s successfully. New balance: %.2f\\n",


amt, receiver, acc->balance);

}
void change_pin(Account *acc) {

int oldpin, newpin, confirm;

printf("Enter current PIN: ");

if (scanf("%d", &oldpin) != 1) { while (getchar() != '\\n');


printf("Invalid input.\\n"); return; }

if (oldpin != acc->pin) {

printf("Current PIN incorrect.\\n");

return;

printf("Enter new 4-digit PIN: ");

if (scanf("%d", &newpin) != 1) { while (getchar() != '\\n');


printf("Invalid input.\\n"); return; }

printf("Confirm new PIN: ");

if (scanf("%d", &confirm) != 1) { while (getchar() != '\\n');


printf("Invalid input.\\n"); return; }

if (newpin != confirm) {

printf("PINs do not match. PIN not changed.\\n");

return;

acc->pin = newpin;

add_transaction(acc, "PIN Change", 0.0, "User changed PIN");

printf("PIN changed successfully.\\n");

void show_menu() {

printf("\\n======== ATM MENU ========\\n");

printf("1. Check Balance\\n");

printf("2. Deposit\\n");

printf("3. Withdraw\\n");
printf("4. Transfer\\n");

printf("5. Mini Statement\\n");

printf("6. Change PIN\\n");

printf("7. Exit\\n");

printf("==========================\\n");

printf("Select option (1-7): ");

int main() {

Account user;

[Link] = 1000.00; // initial balance

[Link] = 1234; // default PIN

user.tx_count = 0;

printf("Welcome to the ATM Transaction Simulator\\n");

if (!authenticate_pin(&user)) {

return 0;

int choice;

while (1) {

show_menu();

if (scanf("%d", &choice) != 1) {

while (getchar() != '\\n');

printf("Invalid choice. Try again.\\n");

continue;

}
switch (choice) {

case 1: check_balance(&user); break;

case 2: deposit(&user); break;

case 3: withdraw(&user); break;

case 4: transfer(&user); break;

case 5: show_mini_statement(&user); break;

case 6: change_pin(&user); break;

case 7:

printf("Thank you for using the ATM. Goodbye!\\n");

return 0;

default:

printf("Invalid option. Please select 1-7.\\n");

return 0;

7. Sample Output

Welcome to the ATM Transaction Simulator

Enter 4-digit PIN: 1234

PIN accepted.

======== ATM MENU ========

1. Check Balance

2. Deposit

3. Withdraw

4. Transfer
5. Mini Statement

6. Change PIN

7. Exit

==========================

Select option (1-7): 2

Enter amount to deposit: 500

Deposited 500.00 successfully. New balance: 1500.00

Select option (1-7): 3

Enter amount to withdraw: 200

Withdrawn 200.00 successfully. New balance: 1300.00

Select option (1-7): 5

----- Mini Statement -----

1) Deposit | 500.00 | 2025-10-26 13:10:15 | Cash deposit

2) Withdraw | 200.00 | 2025-10-26 13:12:42 | Cash withdrawal

-----------------------------------------------

8. Result

The ATM Transaction Simulator was successfully developed and executed. It allows the
user to authenticate using a PIN and perform all basic banking operations such as
checking balance, deposit, withdrawal, fund transfer, and viewing a mini-statement. The
system performs accurate balance updates and transaction tracking, thus simulating the
functioning of an ATM effectively.

9. Conclusion
The project demonstrates practical use of C programming concepts such as functions,
structures, arrays, and control statements in building a real-world application model. It
helps students understand modular programming, data validation, and transaction
handling logic in financial systems. This mini project successfully meets its objective of
simulating an ATM and provides an interactive learning experience for beginners in C
programming.

10. Future Enhancements

1. Adding multiple user accounts.


2. Storing account details and transaction logs in a file.
3. Implementing card number and PIN validation.
4. Creating a GUI-based ATM simulator using C++ or Python.
5. Adding transaction receipts and logging.

You might also like