#include
#include
#include
typedef struct Account {
int accountNumber;
char accountName[50];
double balance;
struct Account* next;
} Account;
Account* head = NULL;
Account* createAccount(int accountNumber, char* accountName, double initialDeposit) {
Account* newAccount = (Account*)malloc(sizeof(Account));
newAccount->accountNumber = accountNumber;
strcpy(newAccount->accountName, accountName);
newAccount->balance = initialDeposit;
newAccount->next = head;
head = newAccount;
return newAccount;
}
void deposit(Account* account, double amount) {
if (account != NULL) {
account->balance += amount;
printf("Deposit successful. New balance: %.2fn", account->balance);
} else {
printf("Account not found.n");
}
}
void withdraw(Account* account, double amount) {
if (account != NULL) {
if (account->balance >= amount) {
account->balance -= amount;
printf("Withdrawal successful. New balance: %.2fn", account->balance);
} else {
printf("Insufficient balance.n");
}
} else {
printf("Account not found.n");
}
}
Account* findAccount(int accountNumber) {
Account* current = head;
while (current != NULL) {
if (current->accountNumber == accountNumber) {
return current;
}
current = current->next;
}
return NULL;
}
void checkBalance(int accountNumber) {
Account* account = findAccount(accountNumber);
if (account != NULL) {
printf("Current balance: %.2fn", account->balance);
} else {
printf("Account not found.n");
}
}
int main() {
Account* acc1 = createAccount(1001, "John Doe", 500.0);
Account* acc2 = createAccount(1002, "Jane Smith", 1000.0);
deposit(acc1, 200.0);
withdraw(acc1, 100.0);
checkBalance(1001);
deposit(acc2, 500.0);
withdraw(acc2, 1200.0);
checkBalance(1002);
return 0;
}