0% found this document useful (0 votes)
3 views7 pages

Ibm Code

The document is a C program that implements a simple banking system allowing users to credit and debit amounts from a bank account. It defines structures for transactions and bank accounts, and provides functions to manage account operations such as crediting, debiting, showing balance, and printing transaction statements. The program runs in a loop, presenting a menu to the user until they choose 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 DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views7 pages

Ibm Code

The document is a C program that implements a simple banking system allowing users to credit and debit amounts from a bank account. It defines structures for transactions and bank accounts, and provides functions to manage account operations such as crediting, debiting, showing balance, and printing transaction statements. The program runs in a loop, presenting a menu to the user until they choose 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 DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

#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;

account.balance = 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