-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbanking_system.c
More file actions
108 lines (87 loc) · 2.46 KB
/
Copy pathbanking_system.c
File metadata and controls
108 lines (87 loc) · 2.46 KB
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
#include<stdio.h>
#include<stdlib.h>
struct node{
int accNo;
char name[50];
float balance;
};
void createAccount(){
struct node a;
FILE *ptr=fopen("account.txt","w");
printf("\nenter Account number: ");
scanf("%d",&a.accNo);
printf("\nenter name: ");
scanf("%s",&a.name);
printf("\nenter balance: ");
scanf("%f",&a.balance);
fprintf(ptr,"%d %s %f",a.accNo,a.name,a.balance);
fclose(ptr);
}
void deposit(){
struct node a;
float amount;
FILE *fp = fopen("account.txt", "r");
fscanf(fp, "%d %s %f", &a.accNo, a.name, &a.balance);
fclose(fp);
printf("Enter Amount to Deposit: ");
scanf("%f", &amount);
a.balance = a.balance + amount;
fp = fopen("account.txt", "w");
fprintf(fp, "%d %s %f", a.accNo, a.name, a.balance);
fclose(fp);
printf("Updated Balance = %.2f\n", a.balance);
}
void withdraw(){
struct node a;
float amount;
FILE *ptr=fopen("account.txt","r");
fscanf(ptr, "%d %s %f", &a.accNo, a.name, &a.balance);
fclose(ptr);
printf("\nEnter Amount to Withdraw: ");
scanf("%f", &amount);
if(amount > a.balance)
{
printf("\nInsufficient Balance!\n");
}
else
{
a.balance = a.balance - amount;
ptr = fopen("account.txt", "w");
fprintf(ptr, "%d %s %f", a.accNo, a.name, a.balance);
fclose(ptr);
printf("Remaining Balance = %.2f\n", a.balance);
}
}
void balanceEnquiry()
{
struct node a;
FILE *fp = fopen("account.txt", "r");
fscanf(fp, "%d %s %f", &a.accNo, a.name, &a.balance);
fclose(fp);
printf("\nAccount Number: %d", a.accNo);
printf("\nName: %s", a.name);
printf("\nBalance: %.2f\n", a.balance);
}
int main(){
int choice;
while(choice!=5){
printf("\n------------BANK MANAGEMENT SYSTEM-----------\n");
printf("1.create account\n2.deposite\n3.withdraw\n4.balance enquiry\n5.exit");
printf("\nenter your choice: ");
scanf("%d",&choice);
switch(choice){
case 1: createAccount();
break;
case 2:deposit();
break;
case 3: withdraw();
break;
case 4: balanceEnquiry();
break;
case 5: exit(0);
break;
default: printf("\ninvalid choice.Try again!");
break;
}
}
}