-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathtransferMoney.c
42 lines (33 loc) · 1.14 KB
/
transferMoney.c
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
#include "bwave.h"
/**
* transferMoney - Transfers money function.
* @balance: the balance
* @lastTransferAmount: last Transfer Amount.
* Return: void
*/
void transferMoney(double* balance, double* lastTransferAmount)
{
char accountName[MAX_LENGTH], accountNumber[MIN_LENGTH], bank[MAX_LENGTH];
double amount;
printf("\nEnter recipient's account name: ");
getchar();
fgets(accountName, sizeof(accountName), stdin);
accountName[strcspn(accountName, "\n")] = '\0'; //This removes the newline character from fgets
printf("Enter recipient's account number: ");
scanf("%s", accountNumber);
getchar();
printf("Enter recipient's bank name: ");
fgets(bank, sizeof(bank), stdin);
bank[strcspn(bank, "\n")] = '\0'; //This removes the newline character from fgets
printf("Enter transfer amount: ");
scanf("%lf", &amount);
if (amount > *balance) {
printf("Insufficient balance for the transfer.\n");
return;
}
//Perform transfer operation.
*balance -= amount;
*lastTransferAmount = amount;
//print reciept with transaction details
printReceipt("Debit Alert", accountName, accountNumber, bank, amount, *balance + amount, *balance);
}