-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBankAccount.c
More file actions
44 lines (39 loc) · 1.1 KB
/
BankAccount.c
File metadata and controls
44 lines (39 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include <stdio.h>
#include <stdlib.h>
#include "BankAccount.h"
BankAccount* create_account(char *name, double initial_balance)
{
BankAccount *new_account = (BankAccount*) malloc(sizeof(BankAccount));
new_account->name = name;
new_account->balance = initial_balance;
return new_account;
}
void deposit(BankAccount *account, double amount)
{
printf("Previous Balance: $%.2f\n", account->balance);
account->balance += amount;
printf("+$%.2f deposited.\n", amount);
printf("New Balance: $%.2f\n", account->balance);
printf("-----------------------\n");
}
void withdraw(BankAccount *account, double amount)
{
printf("Previous Balance: $%.2f\n", account->balance);
if (amount > account->balance)
{
printf("Insufficient funds to withdraw $%.2f.\n", amount);
}
else
{
account->balance -= amount;
printf("-$%.2f withdrawn.\n", amount);
}
printf("New Balance: $%.2f\n", account->balance);
printf("-----------------------\n");
}
void display_account(BankAccount *account)
{
printf("Name: %s\n", account->name);
printf("Current Balance: $%.2f\n", account->balance);
printf("-----------------------\n");
}