-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathATM.c
155 lines (126 loc) · 2.3 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
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<stdbool.h>
void mainmenu();
void erromsg();
void checkbalance(float balance);
void withdraw(float balance);
void deposit(float balance);
void menuexit();
int main()
{
int option,choose;
bool again=true;
float balance;
while(again)
{
mainmenu();
scanf("%d",&option);
FILE*fpointer;
fpointer=fopen("balance.txt","r");
if(fpointer==NULL)
{
printf("Error! File not found!");
return -1;
}
else
{
fscanf(fpointer,"%f",&balance);
}
switch(option)
{
case 1:
system("cls");
checkbalance(balance);
break;
case 2:
system("cls");
withdraw(balance);
break;
case 3:
system("cls");
deposit(balance);
break;
case 4:
system("cls");
menuexit();
return 0;
default:
erromsg();
break;
}
printf("would you like to do a another transaction??????\n");
printf("<1>yes\n");
printf("<2>no\n");
scanf("%d",&choose);
system("CLS");
if(choose==2)
{
again=false;
menuexit();
}
fclose(fpointer);
}
return 0;
}
void mainmenu()
{
printf("============HELLO============\n");
printf("============GOOD MORNING============\n");
printf("============WELCOME TO SAMPATH ATM============\n");
printf("1. Check Balance\n");
printf("2. Withdraw\n");
printf("3. Deposit\n");
printf("4. Exit\n");
}
void erromsg()
{
printf("Invalid Option\n");
}
void checkbalance(float balance)
{
printf("Your Balance is %.2f\n",balance);
}
void withdraw(float balance)
{
FILE*fpointer;
fpointer=fopen("balance.txt","w");
float amount;
bool back=true;
while(back)
{
printf("Enter the amount to withdraw: ");
scanf("%f",&amount);
if(amount>balance)
{
printf("Insufficient Balance\n");
}
else
{
balance=balance-amount;
printf("Please collect your cash\n");
printf("Your Balance is %.2f\n",balance);
back=false;
}
}
fprintf(fpointer,"%.2f",balance);
fclose(fpointer);
}
void deposit(float balance)
{
FILE*fpointer;
fpointer=fopen("balance.txt","w");
float amount;
printf("Enter the amount to deposit: ");
scanf("%f",&amount);
balance=balance+amount;
printf("Your Balance is %.2f\n",balance);
fprintf(fpointer,"%.2f",balance);
fclose(fpointer);
}
void menuexit()
{ system("CLS");
printf("take your recipt\n");
printf("THANK YOU!\n");
}