-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathc-banking-project.c
218 lines (215 loc) · 6.14 KB
/
c-banking-project.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
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#define PASSWORD_LENGTH 20
struct Account
{
int accountNumber;
char name[50];
char password[50];
float balance;
char branch[50];
char ifsc[50];
char mobile[10];
};
//Array to Store accounts
struct Account accounts[100];
int accountCount = 0;
// Function to generate random account number
int randomaccountnumber()
{
srand(time(NULL));
return rand() %90000000000 +1000000000;}
//Function
void addAccount();
void listAccounts();
void removeAccount();
void transactions();
int main() {
int choice;
while (1)
{
// Main menu to Display menu
printf("\n\t*** WELCOME TO NOVA BANK****\t\t\n");
printf("\t\t\t1. Add Account\n");
printf("\t\t\t2. List Accounts\n");
printf("\t\t\t3. Remove Account\n");
printf("\t\t\t4. Transactions\n");
printf("\t\t\t5. Exit\n");
printf("\t\t\tEnter your choice: ");
scanf("%d", &choice);
switch (choice)
{
case 1:
addAccount();
break;
case 2:
listAccounts();
break;
case 3:
removeAccount();
break;
case 4:
transactions();
break;
case 5:
return 0;
default:
printf("Invalid choice. Please enter a valid option.\n");
}
}
return 0;
}
//Function to add new account
void addAccount()
{
if (accountCount < 100)
{
printf("Enter Your Full name: ");
scanf("%s", &accounts[accountCount].name);
printf("Enter Branch name: ");
scanf("%s", &accounts[accountCount].branch);
accounts[accountCount].accountNumber=randomaccountnumber();
printf("Enter account IFSC code: ");
scanf("%s", &accounts[accountCount].ifsc);
printf("Enter password: ");
scanf("%s", &accounts[accountCount].password);
printf("Enter Mobile number: ");
scanf("%d", &accounts[accountCount].mobile);
printf("Enter initial balance: ");
scanf("%f", &accounts[accountCount].balance);
accountCount++;
for (int i = 0; i < accountCount; i++) {
printf("\nWELCOME TO NOVA BANKING!1\n");
printf("Thank you %s for registering your new account in %s Branch\n",accounts[i].name,accounts[i].branch);
printf(" Your account number :%d\n HAPPY BANKING",accounts[i].accountNumber);
}}
else
{
printf("Maximum accounts reached!\n");
}
}
//Function to List all account that you are created
void listAccounts()
{
if (accountCount == 0)
{
printf("No accounts available!\n");
}
else
{
printf("List of Accounts:\n");
for (int i = 0; i < accountCount; i++)
{
printf("Account Number: %d\n", accounts[i].accountNumber);
printf("Account Holder's Name: %s\n", accounts[i].name);
printf("Branch Name: %s\n", accounts[i].branch);
printf("IFSC code: %s\n", accounts[i].ifsc);
printf("Mobile number: %d\n", accounts[i].mobile);
printf("Balance: %.2f\n\n", accounts[i].balance);
}
}
}
//Function to remove an account
void removeAccount()
{
int accountNumber;
printf("Enter account number to delete: ");
scanf("%d", &accountNumber);
for (int i = 0; i < accountCount; i++)
{
if (accounts[i].accountNumber == accountNumber)
{
for (int j = i; j < accountCount - 1; j++)
{
accounts[j] = accounts[j + 1];
}
accountCount--;
printf("Account removed successfully!\n");
return;
}
}
printf("Account not found!\n");
}
//Function to perform transactions
void transactions()
{
int accountNumber;
char password[50];
printf("Enter account number: ");
scanf("%d", &accountNumber);
printf("Enter password: ");
scanf("%s",&password);
for (int i = 0; i < accountCount; i++)
{
if (accounts[i].accountNumber == accountNumber && strcmp(accounts[i].password,password)==0)
{
while (1)
{
printf("\nTransaction of Account %d\n", accountNumber);
printf("1. Deposit\n");
printf("2. Withdraw\n");
printf("3. Transfer\n");
printf("4. Return to main menu\n");
printf("Enter your choice: ");
int choice;
scanf("%d", &choice);
switch (choice)
{
case 1:
float depositAmount;
printf("Enter amount to deposit: ");
scanf("%f", &depositAmount);
accounts[i].balance += depositAmount;
printf("Deposit successful! New balance: %.2f\n", accounts[i].balance);
break;
case 2:
float withdrawAmount;
printf("Enter amount to withdraw: ");
scanf("%f", &withdrawAmount);
if (accounts[i].balance >= withdrawAmount)
{
accounts[i].balance -= withdrawAmount;
printf("Withdrawal successful! New balance: %.2f\n", accounts[i].balance);
}
else
{
printf("Insufficient balance!\n");
}
break;
case 3:
int toAccount;
float transferAmount;
printf("Enter account number to transfer to: ");
scanf("%d", &toAccount);
printf("Enter amount to transfer: ");
scanf("%f", &transferAmount);
for (int j = 0; j < accountCount; j++)
{
if (accounts[j].accountNumber == toAccount)
{
if (accounts[i].balance >= transferAmount)
{
accounts[i].balance -= transferAmount;
accounts[j].balance += transferAmount;
printf("Transfer successful!\n");
}
else
{
printf("Insufficient balance!\n");
}
break;
}
}
break;
case 4:
return;
default:
printf("Invalid choice. Please enter a valid option.\n");
}
}
}
}
printf("INVAILD Account number or password!\n");
}