Simple Banking System
Simple Banking System
h>
#include <stdlib.h>
#include <string.h>
// Define constants
#define MAX_ACCOUNTS 100
// Function prototypes
int createAccount(Account accounts[], int *numAccounts);
int deposit(Account accounts[], int numAccounts);
int withdraw(Account accounts[], int numAccounts);
int displayAccounts(Account accounts[], int numAccounts);
int findAccount(Account accounts[], int numAccounts, int accountNumber);
int main() {
Account accounts[MAX_ACCOUNTS];
int numAccounts = 0;
int choice;
// Main loop
do {
// Display menu
printf("\nSimple Banking System\n");
printf("1. Create Account\n");
printf("2. Deposit\n");
printf("3. Withdraw\n");
printf("4. Display Accounts\n");
printf("5. Exit\n");
printf("Enter your choice: ");
scanf("%d", &choice);
Account newAccount;
newAccount.accountNumber = *numAccounts + 1;
printf("Enter name: ");
scanf("%s", newAccount.name);
newAccount.balance = 0.0;
accounts[*numAccounts] = newAccount;
(*numAccounts)++;
if (amount < 0) {
printf("Invalid amount. Please enter a positive value.\n");
return -1;
}
accounts[index].balance += amount;
printf("Deposit successful. New balance: %.2f\n", accounts[index].balance);
return 0;
}
if (amount < 0) {
printf("Invalid amount. Please enter a positive value.\n");
return -1;
}
accounts[index].balance -= amount;
printf("Withdrawal successful. New balance: %.2f\n", accounts[index].balance);
return 0;
}
printf("\nAccount List:\n");
for (int i = 0; i < numAccounts; i++) {
printf("Account Number: %d, Name: %s, Balance: %.2f\n",
accounts[i].accountNumber, accounts[i].name, accounts[i].balance);
}
return 0;
}