Files
BankManager/transaction.c
T

103 lines
2.8 KiB
C
Raw Normal View History

2026-04-06 21:36:26 +08:00
#include <stdio.h>
#include <stdlib.h>
#include "bank.h"
extern STACCOUNT g_astAccounts[];
extern int g_iAccCount;
2026-04-22 17:32:22 +08:00
/* 函数功能:处理用户的存款操作
需要什么步骤?
* 参数:无
* 存款信息要写入全局变量g_astAccounts中
* 返回值:无
* 存款失败怎么处理?
2026-04-06 21:36:26 +08:00
*/
void Deposit(int id)
{
int amount;
int temp_password;
while (1) {
2026-04-22 17:32:22 +08:00
printf("请输入存款金额");
2026-04-06 21:36:26 +08:00
scanf("%d",&amount);
if (amount>0) {
break;
}
2026-04-22 17:32:22 +08:00
printf("?你存给我存个负的?重新说存多少");
2026-04-06 21:36:26 +08:00
}
2026-04-22 17:32:22 +08:00
printf("请输入密码");
2026-04-06 21:36:26 +08:00
while (1) {
scanf("%d",&temp_password);
if (g_astAccounts[FindAccount(id)].password==temp_password) {
g_astAccounts[FindAccount(id)].balance+=amount;
printf("success");
QueryBalance(id);
2026-05-08 11:46:09 +08:00
EnqueueLog(id, "Deposit", amount, g_astAccounts[FindAccount(id)].balance);
2026-04-06 21:36:26 +08:00
SaveData();
break;
}
else
{
{
2026-04-22 17:32:22 +08:00
printf("密码错误,请重新输入");
2026-04-06 21:36:26 +08:00
}
}
}
}
2026-04-22 17:32:22 +08:00
/* 函数功能:处理用户的取款操作
需要什么步骤?
* 参数:无
* 取款后,账户信息要写入全局变量g_astAccounts中
* 返回值:无
* 取款失败怎么处理?
2026-04-06 21:36:26 +08:00
*/
void Withdraw(int id)
{
int amount;
int temp_password;
while (1) {
2026-04-22 17:32:22 +08:00
printf("请输入取款金额");
2026-04-06 21:36:26 +08:00
scanf("%d",&amount);
if (amount>0) {
break;
}
2026-04-22 17:32:22 +08:00
printf("?取款怎么能取负的呢");
2026-04-06 21:36:26 +08:00
}
while (1) {
2026-04-22 17:32:22 +08:00
printf("请输入密码");
2026-04-06 21:36:26 +08:00
scanf("%d",&temp_password);
if (g_astAccounts[FindAccount(id)].password==temp_password) {
if (g_astAccounts[FindAccount(id)].balance>amount) {
g_astAccounts[FindAccount(id)].balance-=amount;
2026-05-08 11:46:09 +08:00
EnqueueLog(id, "Withdraw", amount, g_astAccounts[FindAccount(id)].balance);
2026-04-06 21:36:26 +08:00
printf("success");
QueryBalance(id);
SaveData();
return;
}
else {
2026-04-22 17:32:22 +08:00
printf("有那么多钱吗你就取?\n");
2026-04-06 21:36:26 +08:00
QueryBalance(id);
return;
}
}
else {
2026-04-22 17:32:22 +08:00
printf("密码错误,请重新输入");
2026-04-06 21:36:26 +08:00
}
}
}
2026-04-22 17:32:22 +08:00
/* 函数功能:处理用户查询余额操作
需要什么步骤?
* 参数:无
* 查询后全局变量是否需要变化?
* 返回值:无
* 查询失败怎么处理?
2026-04-06 21:36:26 +08:00
*/
void QueryBalance(int id)
{
2026-04-22 17:32:22 +08:00
printf("你现在还有%f块\n",g_astAccounts[FindAccount(id)].balance);
2026-04-06 21:36:26 +08:00
return;
}