graph
This commit is contained in:
+57
-2
@@ -31,7 +31,7 @@ void Deposit(int id)
|
||||
g_astAccounts[FindAccount(id)].balance+=amount;
|
||||
printf("success");
|
||||
QueryBalance(id);
|
||||
EnqueueLog(id, "Deposit", amount, g_astAccounts[FindAccount(id)].balance);
|
||||
EnqueueLog(id, "Deposit", amount, g_astAccounts[FindAccount(id)].balance, -1);
|
||||
SaveData();
|
||||
break;
|
||||
}
|
||||
@@ -69,7 +69,7 @@ void Withdraw(int id)
|
||||
if (g_astAccounts[FindAccount(id)].password==temp_password) {
|
||||
if (g_astAccounts[FindAccount(id)].balance>amount) {
|
||||
g_astAccounts[FindAccount(id)].balance-=amount;
|
||||
EnqueueLog(id, "Withdraw", amount, g_astAccounts[FindAccount(id)].balance);
|
||||
EnqueueLog(id, "Withdraw", amount, g_astAccounts[FindAccount(id)].balance, -1);
|
||||
printf("success");
|
||||
QueryBalance(id);
|
||||
SaveData();
|
||||
@@ -100,3 +100,58 @@ void QueryBalance(int id)
|
||||
printf("你现在还有%f块\n",g_astAccounts[FindAccount(id)].balance);
|
||||
return;
|
||||
}
|
||||
|
||||
void Transfer(int from_id)
|
||||
{
|
||||
int to_id;
|
||||
int amount;
|
||||
int temp_password;
|
||||
int from_idx = FindAccount(from_id);
|
||||
int to_idx;
|
||||
|
||||
printf("请输入目标账户ID: ");
|
||||
scanf("%d", &to_id);
|
||||
|
||||
to_idx = FindAccount(to_id);
|
||||
if (to_idx == -1) {
|
||||
printf("目标账户不存在!\n");
|
||||
return;
|
||||
}
|
||||
if (from_id == to_id) {
|
||||
printf("不能给自己转账!\n");
|
||||
return;
|
||||
}
|
||||
|
||||
while (1) {
|
||||
printf("请输入转账金额: ");
|
||||
scanf("%d", &amount);
|
||||
if (amount > 0) break;
|
||||
printf("金额必须为正数!\n");
|
||||
}
|
||||
|
||||
printf("请输入密码验证身份: ");
|
||||
while (1) {
|
||||
scanf("%d", &temp_password);
|
||||
if (g_astAccounts[from_idx].password == temp_password) {
|
||||
if (g_astAccounts[from_idx].balance >= amount) {
|
||||
g_astAccounts[from_idx].balance -= amount;
|
||||
g_astAccounts[to_idx].balance += amount;
|
||||
EnqueueLog(from_id, "Transfer", amount,
|
||||
g_astAccounts[from_idx].balance, to_id);
|
||||
EnqueueLog(to_id, "Receive", amount,
|
||||
g_astAccounts[to_idx].balance, from_id);
|
||||
printf("转账成功! %d -> %d, 金额: %d\n",
|
||||
from_id, to_id, amount);
|
||||
printf("当前余额: %.2f\n", g_astAccounts[from_idx].balance);
|
||||
SaveData();
|
||||
return;
|
||||
} else {
|
||||
printf("余额不足! 当前余额: %.2f\n",
|
||||
g_astAccounts[from_idx].balance);
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
printf("密码错误,请重新输入: ");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user