-
Notifications
You must be signed in to change notification settings - Fork 0
/
atm.c
184 lines (158 loc) · 4.51 KB
/
atm.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
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int generatePin();
void welcomeLog();
void atmOptions();
void cashWithdrawal();
void balanceEnquiry();
void cashDeposit();
void receipter();
void Exit();
static int InitialAmount,pin;
int main()
{
welcomeLog();
atmOptions();
}
int generatePin(){
srand(time(NULL));
int num=rand();
if(num/10==0)//1 digit
{
num=num+1234;
}
else if(num/100==0)
{
num=num+1100;
}
else if(num/1000==0)
{
num=num+4321;
}
else {
int tempSum = (num/10000)*10000;// 1111/10000=0.1 = 0.1*10000 => 1111
num = num - tempSum;// 1111-1111
}
if(num / 1000 == 0){
num = num + 2521;
}
return num;
}
void welcomeLog(){
printf("\n*\t Welcome to SRM Bank\t*\n");
int cardnumber;
printf("//////////////////////////////////////");
printf("\n\nInput Your Card Number: ");
scanf("%d",&cardnumber);
printf("\n//////////////////////////////////////\n");
printf("Your Details:--->");
srand(time(0));
InitialAmount=rand()%10000+10000;
printf("\nInitial Amount: %d",InitialAmount);
pin = generatePin();
printf("\nYour Pin: %d",pin);
}
void atmOptions()
{
printf("\n///////////////////////\n\n");
printf("1.-> Cash Withdrawal\n");
printf("2.-> Cash Deposit\n");
printf("3.-> Balance Enquiry\n");
printf("4.-> Exit");
printf("\n\n///////////////////////");
printf("\n\nUser Input -> ");
int selectedOption;
scanf("%d",&selectedOption);
printf("\n///////////////////////\n\n");
int tempPin;
switch(selectedOption){
case 1:
cashWithdrawal();
break;
case 2:
cashDeposit();
break;
case 3:
printf("Enter You Pin -> ");
scanf("%d",&tempPin);
if(tempPin == pin){
balanceEnquiry();
}else{
printf("\nThe pin was incorrect");
}
break;
case 4:
Exit();
break;
default:printf("Invalid Input ");
Exit();
break;
}
}
void cashWithdrawal(){
printf("Enter You Pin -> ");
int tempPin;
scanf("%d",&tempPin);
if(tempPin == pin){
printf("\n/////////////////////////////\n");
printf("\nEnter Withdrawal Amount : ");
int withdrawalAmount;
scanf("%d",&withdrawalAmount);
if(withdrawalAmount > InitialAmount){
printf("\nInsufficient Amount in Your Account");
balanceEnquiry();
}else{
printf("\nWithdrawal Successfull !! Please Take Your Receipt");
InitialAmount = InitialAmount - withdrawalAmount;
receipter(InitialAmount,withdrawalAmount,1);
balanceEnquiry();
}
}else{
printf("\nThe pin was incorrect");
Exit();
}
}
void receipter(int availableAmount , int Amount, int checkWorD){
time_t t;
time(&t);
FILE *filePointer;
filePointer = fopen("BankReceipt.txt","w");
fprintf(filePointer,"\n\t**SRM BANK OF SYRIA**\n\n\n");
fprintf(filePointer,"Transancion Done on : %s\n\n",ctime(&t));
fprintf(filePointer,"Txn No -> 36521\n");
fprintf(filePointer,"Response Code -> 000\n");
if(checkWorD == 1){
fprintf(filePointer,"Withdrawal Amount -> Rs.%d\n",Amount);
}else{
fprintf(filePointer,"Deposited Amount -> Rs.%d\n",Amount);
}
fprintf(filePointer,"Mod Bal -> Rs.00\n");
fprintf(filePointer,"Available Balance -> Rs.%d\n\n",availableAmount);
fprintf(filePointer,"Note -> If this transanction is not acceded by you . Please Report it to 1800-456-1356");
}
void cashDeposit(){
printf("Enter Your Pin : ");
int tempPin;
scanf("%d",&tempPin);
if(tempPin == pin){
printf("\n////////////////////////\n\nEnter Deposit Amount : ");
int tempDepoAmount;
scanf("%d",&tempDepoAmount);
InitialAmount = InitialAmount + tempDepoAmount;
printf("\nDeposit Successfull !! Don't forget to take your receipt");
receipter(InitialAmount,tempDepoAmount,0);
balanceEnquiry();
}else{
printf("\nThe pin was incorrect");
Exit();
}
}
void balanceEnquiry(){
printf("\n---------------------------------");
printf("\nAvailable Balance : Rs.%d",InitialAmount);
Exit();
}
void Exit(){
printf("\n\nThank You ! Visit Again ");
}