-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcustomer.c
202 lines (163 loc) · 5.87 KB
/
customer.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
/*
Name: Nicholas Paladino
James Sigler
Section: 502
Purpose: To create functions and give the their functionality
when accessing the user account type in main meniu
*/
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
#include <ctype.h>
//include header files
#include "customer.h"
#include "administrator.h"
#define MAX_TRANSACTION 5000
/******************************************************************************************
* Name: ViewBalance
* Purpose: To display the balance of the account that is currently logged in.
* Parameters: Account* accountCurr - pointer to the current
* account structure information
*
* Side effects: None
*******************************************************************************************/
void ViewBalance(Account* accountCurr)
{
printf("Your balance is: %.2f\n", accountCurr -> balance);
}
/******************************************************************************************
* Name: depositMoney
* Purpose: To take a user defined amount and add it to their account's balance.
* Parameters: Account* accountCurr - pointer to the current
* account structure information
*
* Side effects: Adds to the balance of the current users account
*******************************************************************************************/
void depositMoney(Account* accountCurr)
{
double amountToDeposit;
inputDeposit:
printf("Enter amount to deposit(maximum of $5000): ");
scanf("%lf", &amountToDeposit);
//making sure the deposit amount is valid
if((amountToDeposit <= 0) || (amountToDeposit > MAX_TRANSACTION))
{
printf("Invalid deposit amount\n");
//repeating if not valid
goto inputDeposit;
}
//adding the deposit to the balance
accountCurr -> balance += amountToDeposit;
printf("New balance: %.2lf\n\n", accountCurr->balance);
}
/******************************************************************************************
* Name: transferMoney
* Purpose: To take an amount of money from the current users account and transfer
* the amount to another specified user's account.
* Parameters: Account* accountCurr - pointer to the current
* account structure information
* Account* p[] - pointer to another users account to transfer money to.
*
* Side effects: Subtracts the amount to transfer from the current users account and adds
* that amount to the another user specified by the current user.
*******************************************************************************************/
void transferMoney(Account* accountCurr, Account p[])
{
double amountToTransfer;
char accountID[6];
inputID:
//accessing other account's ID
printf("Enter account number to transfer to: ");
scanf("%s", accountID);
//making sure that money will not transfer to the same account
if (strcmp(accountID, accountCurr -> accountID) == 0)
{
printf(" \n Cannot transfer to same account, please enter a valid user ID. \n");
goto inputID;
}
//making sure the account to transfer to is valid
for(int n = 0; n < strlen(accountID); n++)
{
if((strlen(accountID) > 5) || (isdigit(accountID[n]) == false))
{
printf("Invalid account ID\n");
goto inputID;
}
}
inputTransfer:
printf("Enter amount to transfer to %s :", accountID);
scanf("%lf", &amountToTransfer);
//making sure they are transfering a valid amount of money
if(amountToTransfer <= 0 || amountToTransfer > MAX_TRANSACTION)
{
printf("Invalid amount:\n");
goto inputTransfer;
}
//making sure the user cannot give more than they have
if(amountToTransfer > accountCurr -> balance)
{
printf("Insufficient funds, re-enter amount or contact administrator for assistance. \n");
goto inputTransfer;
}
//checking every user for the correct account to transfer to
for(int i = 0; i < MAX_CUSTOMERS; i++)
{
if(strcmp(p[i].accountID, accountID) == 0)
{
//subtracting the amount from the current account
accountCurr -> balance -= amountToTransfer;
//adding the amount to the specified account
p[i].balance += amountToTransfer;
break;
}
}
}
/******************************************************************************************
* Name: withdrawMoney
* Purpose: To take money out of the current account and physically give it to the user.
* Parameters: Account* accountCurr - pointer to the current
* account structure information
*
* Side effects: Subtract money from the current users account balance.
*******************************************************************************************/
void withdrawMoney(Account* accountCurr)
{
double amountToWithdraw;
inputWithdraw:
//entering amount to withdraw
printf("Enter amount of money to withdraw: ");
scanf("%lf", &amountToWithdraw);
//making sure the user withdraws a positive number
if(amountToWithdraw <= 0)
{
printf("Invalid amount:\n");
goto inputWithdraw;
}
//making sure they do not withdraw more than they have
if(amountToWithdraw > accountCurr -> balance)
{
printf("Insufficient funds, re-enter amount or contact administrator for assistance. \n");
goto inputWithdraw;
}
//subtracting the money from their balance
accountCurr->balance -= amountToWithdraw;
printf("%lf\n", accountCurr->balance);
}
/******************************************************************************************
* Name: viewAccountInfo
* Purpose: To display all of the users information excluding their password.
* Parameters: Account* p - pointer to the current
* account structure information
*
* Side effects: None
*******************************************************************************************/
void viewAccountInfo(Account* p)
{
printf("\nFirst Name: %s\n", p->firstName);
printf("Last Name: %s\n", p->lastName);
printf("City: %s\n", p->city);
printf("State: %s\n", p->state);
printf("Phone Number: %s\n", p->phoneNumber);
printf("Account ID: %s\n", p->accountID);
printf("Balance: %.2f\n\n", p->balance);
}