0% found this document useful (0 votes)
21 views4 pages

Code

The document contains a C program for a simple bank account management system that allows users to credit and debit amounts, show the current balance, and print a transaction statement. It defines two structures: BankAccount and Transaction, and implements functions for each operation. The program runs in a loop, providing a menu for user interaction until the user chooses to exit.

Uploaded by

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

Code

The document contains a C program for a simple bank account management system that allows users to credit and debit amounts, show the current balance, and print a transaction statement. It defines two structures: BankAccount and Transaction, and implements functions for each operation. The program runs in a loop, providing a menu for user interaction until the user chooses to exit.

Uploaded by

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

#include <stdio.

h>

#include <string.h>

#define MAX_TRANSACTIONS 100

typedef struct {

char type[10]; // "Credit" or "Debit"

float amount;

float balance_after;

} Transaction;

typedef struct {

char account_holder[50];

float balance;

Transaction transactions[MAX_TRANSACTIONS];

int transaction_count;

} BankAccount;

// Function to credit amount

void credit(BankAccount *acc, float amount) {

if (amount <= 0) {

printf("Enter a valid amount to credit.\n");

return;

acc->balance += amount;

if (acc->transaction_count < MAX_TRANSACTIONS) {

Transaction t = {"Credit", amount, acc->balance};

acc->transactions[acc->transaction_count++] = t;

printf("Credited ₹%.2f. Current Balance: ₹%.2f\n", amount, acc->balance);

// Function to debit amount

void debit(BankAccount *acc, float amount) {


if (amount <= 0) {

printf("Enter a valid amount to debit.\n");

return;

if (amount > acc->balance) {

printf("Insufficient balance.\n");

return;

acc->balance -= amount;

if (acc->transaction_count < MAX_TRANSACTIONS) {

Transaction t = {"Debit", amount, acc->balance};

acc->transactions[acc->transaction_count++] = t;

printf("Debited ₹%.2f. Current Balance: ₹%.2f\n", amount, acc->balance);

// Function to show balance

void show_balance(BankAccount *acc) {

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

// Function to print transaction statement

void print_statement(BankAccount *acc) {

printf("\nTransaction History for %s:\n", acc->account_holder);

if (acc->transaction_count == 0) {

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

return;

for (int i = acc->transaction_count - 1; i >= 0; i--) {

printf("%s: ₹%.2f, Balance after: ₹%.2f\n",

acc->transactions[i].type,

acc->transactions[i].amount,

acc->transactions[i].balance_after);

}
}

int main() {

BankAccount account;

[Link] = 0;

account.transaction_count = 0;

printf("Enter account holder name: ");

fgets(account.account_holder, sizeof(account.account_holder), stdin);

account.account_holder[strcspn(account.account_holder, "\n")] = '\0'; // Remove newline

int choice;

float amt;

while (1) {

printf("\n--- Bank Account Menu ---\n");

printf("1. Credit\n2. Debit\n3. Show Balance\n4. Print Statement\n5. Exit\n");

printf("Choose an option: ");

scanf("%d", &choice);

switch (choice) {

case 1:

printf("Enter amount to credit: ₹");

scanf("%f", &amt);

credit(&account, amt);

break;

case 2:

printf("Enter amount to debit: ₹");

scanf("%f", &amt);

debit(&account, amt);

break;

case 3:

show_balance(&account);

break;
case 4:

print_statement(&account);

break;

case 5:

printf("Exiting. Thank you!\n");

return 0;

default:

printf("Invalid choice. Please try again.\n");

You might also like