-
Notifications
You must be signed in to change notification settings - Fork 0
/
Atmstimulator.c
178 lines (160 loc) · 4.92 KB
/
Atmstimulator.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
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX_TRANSACTIONS 100
int i;
typedef struct
{
char type[20]; // Deposit, Withdraw, Transfer
float amount; // Amount of the transaction
char recipient[20]; // For transfers, store the recipient
float balanceAfter; // Balance after the transaction
} Transaction;
typedef struct
{
char name[20]; // Name of the user
float balance; // Account balance
char password[20]; // Password for the user
Transaction history[MAX_TRANSACTIONS]; // Transaction history
int transactionCount; // Number of transactions
} Deposit;
Deposit deposit[3] = {
{"John", 20000, "1234", {}, 0},
{"Ana", 30000, "4567", {}, 0},
{"George", 24000, "7890", {}, 0}};
// Function to add a transaction to history
void addTransaction(const char *type, float amount, const char *recipient, float balanceAfter)
{
Transaction *t = &deposit[i].history[deposit[i].transactionCount++];
strcpy(t->type, type);
t->amount = amount;
strcpy(t->recipient, recipient);
t->balanceAfter = balanceAfter;
}
void withdrawmoney()
{
float amount;
printf("\nEnter the amount to withdraw: ");
scanf("%f", &amount);
if (amount > deposit[i].balance)
{
printf("\nInsufficient balance.");
}
else
{
deposit[i].balance -= amount;
printf("\nWithdrawal successful. Current balance: %.2f", deposit[i].balance);
// Record the transaction
addTransaction("Withdraw", amount, "-", deposit[i].balance);
}
}
void transfer()
{
float amount;
char recipient[20];
printf("\nEnter the recipient's name: ");
scanf("%s", recipient);
printf("Enter the amount to transfer: ");
scanf("%f", &amount);
// Check if recipient exists
for (int j = 0; j < 3; j++)
{
if (strcmp(deposit[j].name, recipient) == 0)
{
if (amount > deposit[i].balance)
{
printf("\nInsufficient balance.");
return;
}
else
{
deposit[i].balance -= amount;
deposit[j].balance += amount;
printf("\nTransfer successful. Your current balance: %.2f", deposit[i].balance);
// Record the transaction for both users
addTransaction("Transfer to", amount, recipient, deposit[i].balance);
Transaction t = {"Transfer from", amount, "", deposit[j].balance};
strcpy(t.recipient, deposit[i].name); // Copy sender's name
deposit[j].history[deposit[j].transactionCount++] = t;
return;
}
}
}
printf("\nRecipient not found.");
}
void checkbalance()
{
printf("\nCurrent balance: %.2f", deposit[i].balance);
}
void depositAmount()
{
float amount;
printf("\nEnter the amount to be deposited: ");
scanf("%f", &amount);
deposit[i].balance += amount;
printf("\nDeposit successful. Current balance: %.2f", deposit[i].balance);
// Record the transaction
addTransaction("Deposit", amount, "-", deposit[i].balance);
}
// Function to view transaction history
void viewTransactionHistory()
{
printf("\nTransaction History for %s:\n", deposit[i].name);
for (int j = 0; j < deposit[i].transactionCount; j++)
{
Transaction *t = &deposit[i].history[j];
printf("Type: %s | Amount: %.2f | Recipient: %s | Balance After: %.2f\n", t->type, t->amount, t->recipient, t->balanceAfter);
}
}
void operations()
{
int choice;
while (1)
{
printf("\nSelect the operation you want to perform:\n");
printf("1. Deposit\n2. Check Balance\n3. Withdraw Money\n4. Transfer Money\n5. View Transaction History\n6. Exit\n");
scanf("%d", &choice);
switch (choice)
{
case 1:
depositAmount();
break;
case 2:
checkbalance();
break;
case 3:
withdrawmoney();
break;
case 4:
transfer();
break;
case 5:
viewTransactionHistory();
break;
case 6:
exit(0);
default:
printf("\nInvalid operation. Try again.");
}
}
}
int main()
{
char name[20], password[20];
printf("\n***************************ATM STIMULATOR****************************");
printf("\nEnter the username: ");
scanf("%s", name);
printf("Enter the password: ");
scanf("%s", password);
for (i = 0; i < 3; i++)
{
if (strcmp(deposit[i].name, name) == 0 && strcmp(deposit[i].password, password) == 0)
{
printf("\nAccess granted.");
operations();
return 0; // Exit after operations are complete
}
}
printf("\nInvalid username or password. Try again.");
return 0; // Exit if access is denied
}