-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathATM-Using-File_Handling.c
270 lines (209 loc) · 9.63 KB
/
ATM-Using-File_Handling.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
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
//For Info About Program check About Section from NSTTPKS Bank Service mainmenu.
#include <stdio.h>
#include <stdlib.h> //used only for goto statement
#include <string.h> // used for comparing Username string literal
#include <time.h> // Used to show time of transaction
int transactionTime()
{
FILE *fptr2;
fptr2 = fopen("C:/Users/SHIVSHANKAR/Desktop/folder/Transaction_History.txt","a");
printf("\nSession Time Added to Transaction_History.txt file.\n-----------------------------------");
time_t t;
time(&t);
fprintf(fptr2,"\n%s ",ctime(&t));
fclose(fptr2);
return 0;
}
int accountUpdate()
{
FILE *fptr1;
fptr1 = fopen("C:/Users/SHIVSHANKAR/Desktop/folder/Account_Details.txt","a");
printf("\nSession Time Added to Account_Details.txt file.\n----------------------------------");
printf("\nUpdated Account_Details.txt file.\n----------------------------------");
time_t t;
time(&t);
fprintf(fptr1,"\n====================\n%s=================== ",ctime(&t));
fclose(fptr1);
return 0;
}
unsigned long amount, deposit, withdraw, exchange, exchangedAmount;
int choice, pin, k, currecyExchange;
char transaction = 'y';
char name[20];
FILE *fptr1;
FILE *fptr2;
FILE *fptr3;
void main()
{
Name:
printf("\nEnter Your Username: ");//Asks User to enter their username only "Prakash" accepted.
scanf("%s", name);
if (strcmp(name, "Sagar") == 0)//strcmp function compare the Username string literal to "Prakash"
{
while (pin != 1234) //if Password is 1234 only then the account will open
{
printf("Enter Your Secret Pin Number: ");
scanf("%d", & pin);
if (pin != 1234)
{
printf("Please Enter Valid Password! \a\n");
}
}
}
else
{
printf("Invalid Username"); //Invalid username
goto Name;//Jumps to the start of main Function
}
fptr3 = fopen("C:/Users/SHIVSHANKAR/Desktop/folder/Account_Balance.txt","r");
printf("-----------------------------\nOpened Account_Balance.txt file.");
if(fptr3 == NULL)
{
printf("Error!");
exit(1);
}
fptr2 = fopen("C:/Users/SHIVSHANKAR/Desktop/folder/Transaction_History.txt","a");
printf("\nOpened Transaction_History.txt file.\n----------------------------------\n");
transactionTime();
if(fptr2 == NULL)
{
printf("Error!");
exit(1);
}
printf("\nFetching Account Balance!");
while (fscanf(fptr3, "%lu", &amount) == 1)
{
printf("\nAccount Balance Fetched Successfully!\n");
}
printf("\nAccount Balance: %lu \n", amount);
fclose(fptr3);
do
{
printf("\n Hello, %s", name);
printf("\n*****Welcome to NSTTPKS Bank ATM Service*****\n"); //NSTTPKS bank ATM Main Menu.
printf("1. Check Balance\n");
printf("2. Withdraw Cash\n");
printf("3. Deposit Cash\n");
printf("4. Currency Exchange\n");
printf("5. About NSTTPKS Bank\n");
printf("6. Quit\n");
printf("********************\n\n");
printf("Enter Your Choice: "); // choice is an integer value which is used for switch case
scanf("%d", & choice);
switch (choice)
{
case 1: //This case simply shows current balance in account
printf("\n Your Balance is: Rs.%lu ", amount);
fprintf(fptr2,"\nShown Balance Amount: Rs.%lu \n",amount);
break;
case 2: //This case is used to withdraw cash from the user account, minimum ammount should be 500 in account
//Balance can only be withdrawn in Multiples of 100
printf("\n Enter the Amount (Multiples of 100) to Withdraw (500 Minimum Balance Required in Account): ");
scanf("%lu", &withdraw);
if (withdraw % 100 != 0)
{
printf("\n Please Enter the Amount in Multiples of 100");
}
else if (withdraw > (amount - 500))
{
printf("\n Insufficient Balance, Minimum Balance Couldn't Be Less Then 500 in Account");
}
else
{
amount = amount - withdraw;
printf("\n\n Please Collect Cash");
printf("\n Your Current Balance is Rs.%lu", amount);
fprintf(fptr2,"\nAmount Withdrawn: Rs.%lu \n",withdraw);
fprintf(fptr2,"\nYour Current Balance is Rs.%lu \n", amount);
}
break;
case 3: //This case is used to Deposit the money in bank account
printf("\nEnter the Amount to Deposit: Rs.");
scanf("%lu", &deposit);
amount = amount + deposit;
printf("\n Your Balance is Rs.%lu", amount);
fprintf(fptr2,"\nAmount Deposited: Rs. %lu \n", deposit);
fprintf(fptr2,"Your Current Balance is Rs.%lu \n", amount);
break;
case 4: //This case is used for Currency exchange only $,€,¥ are accepted at the moment
printf("\nEnter the Amount You Want to Exchange: Rs."); //Currency to be exchanged from main balance
scanf("%lu", &exchange);
printf("\nChoose the Currency to Exchange Into\n"); //Currency Selection menu, To which Currency you need to convertinto
printf("1. US Dollar\n"); //US $ Current Exchange rate(30 Aug, 2021): 100 Rupee = $1.36
printf("2. European Euro\n"); //European € Current Exchange rate(30 Aug, 2021): 100 Rupee = €1.15
printf("3. Japanese Yen\n"); //Japanese ¥ Current Exchange rate(30 Aug, 2021): 100 Rupee = ¥149.52
printf("\nPlease Enter Your Choice: ");
scanf("%d", & currecyExchange);
switch(currecyExchange)
{
case 1: //Exchange into USD
printf("\nAmount You Want to Exchange: Rs.%lu", exchange);
amount= amount-exchange;
exchangedAmount = (exchange/73.49) ;
printf("\nAmount Rs.%lu Exchanged in $%lu\n", exchange, exchangedAmount);
fprintf(fptr2,"\nAmount Rs.%lu Exchanged in $%lu \n",exchange, exchangedAmount);
printf("\n\nPlease Collect Cash\n");
break;
case 2: //Exchange into EUR
printf("\nAmount You Want to Exchange: Rs.%lu", exchange);
amount= amount-exchange;
exchangedAmount = (exchange/86.68) ;
printf("\nAmount Rs.%lu Exchanged in %lu Euros\n", exchange, exchangedAmount);
fprintf(fptr2,"\nAmount Rs.%lu Exchanged in €%lu \n",exchange, exchangedAmount);
printf("\n\nPlease Collect Cash\n");
break;
case 3: //Exchange into JPY
printf("\nAmount You Want to Exchange: Rs.%lu", exchange);
amount= amount-exchange;
exchangedAmount = (exchange*1.49) ;
printf("\nAmount Rs.%lu Exchanged in %lu Yens\n", exchange, exchangedAmount);
fprintf(fptr2,"\nAmount Rs.%lu Exchanged in ¥%lu \n",exchange, exchangedAmount);
printf("\n\nPlease Collect Your Cash\n");
break;
}
fprintf(fptr2,"Your Current Account Balance is Rs.%lu \n", amount);
printf("Your Balance is Rs.%lu", amount);//Balance after Exchanged
break;
case 5: //About and Credit
printf("\n\n\n============Welcome to NSTTPKS Bank ATM About Section============\n\n\n");
printf("Our Name NSTTPKS is Formed of Initials of Each of Our Project Group Member Name.\n");
printf("That is:(In Alphabetically Ascending Order)\n");
printf("Neezam Ali\nSonali Rawat\nTeesha\nTanu\nPrakash\nKirty\nSagar Goswami\n");
printf("\n\nThis Project of Atm Machine Code Contains the Following Functionality:\n");
printf("1. Check the Balance\n2. Withdrawn Cash\n3. Deposit Cash\n4. Currency Exchange to\n\t1. USD \n\t2. EUR \n\t3. JPY\n5. About NSTTPKS ATM\n\n\n\n");
printf("Keeping a Record of Transaction History\n");
break;
case 6:
k = 1;
goto jump;
default:
printf("\n Invalid Choice, Please Enter a Valid Choice.");
}
// to Repeat the Last Transcation Press Y, Or choose a option from Menu Below
printf("\n\nDo U Wish to Repeat the Last Operation/transaction: Then Press 'y', or Press Any Key(Except Y/n) to Return to Main Menu: Press 'n' to Exit.\n");
fflush(stdin);
scanf("%c", & transaction);
if (transaction == 'n' || transaction == 'N')
k = 1;
}
while (!k);
jump:
fptr1 = fopen("C:/Users/SHIVSHANKAR/Desktop/folder/Account_Details.txt","a");
printf("-----------------------------\nOpened Account_Details.txt file.");
if(fptr1 == NULL)
{
printf("Error!");
exit(1);
}
fptr3 = fopen("C:/Users/SHIVSHANKAR/Desktop/folder/Account_Balance.txt","w");
printf("\nOpened Account_Balance.txt file.");
accountUpdate();
fprintf(fptr3,"%lu",amount);
printf("Overwritten Account_Balance.txt");
fprintf(fptr1,"\nUpdated Account Balance: Rs.%lu",amount);
fprintf(fptr2,"=====================Session End=======================");
fclose(fptr1);
fclose(fptr2);
fclose(fptr3);
printf("\n\nThank You for Using NSTTPKS Bank ATM.\n Have a Nice Day.");
}