C语言实现ATM转账功能 - 代码示例
#include<stdio.h> #define MAX_ACCOUNTS 10 typedef struct{ int accountNo; //账号 int balance; //余额 } Account; Account bankAccounts[MAX_ACCOUNTS] = { {1001, 10000}, {1002, 20000}, {1003, 15000}, {1004, 12000}, {1005, 18000}, {1006, 9000}, {1007, 5000}, {1008, 1000}, {1009, 7000}, {1010, 3000} }; int main(){ int i, accountNo = -1, transferAccountNo, transferAmount; printf('转账服务\n'); printf('请输入对方账号:'); scanf('%d', &transferAccountNo); while (transferAccountNo < 100 || transferAccountNo > 999) { printf('账号错误,请重新输入对方账号:'); scanf('%d', &transferAccountNo); } for (i = 0; i < MAX_ACCOUNTS; i++) { if (bankAccounts[i].accountNo == transferAccountNo) { accountNo = i; break; } } if (accountNo == -1) { printf('账号不存在\n'); } else { printf('请输入转账金额:'); scanf('%d', &transferAmount); while (transferAmount <= 0) { printf('转账金额不能小于等于0,请重新输入转账金额:'); scanf('%d', &transferAmount); } if (bankAccounts[0].balance >= transferAmount) { bankAccounts[0].balance -= transferAmount; bankAccounts[accountNo].balance += transferAmount; printf('转账成功\n'); } else { printf('余额不足\n'); } } printf('功能界面\n'); return 0; }
原文地址: https://www.cveoy.top/t/topic/oDfe 著作权归作者所有。请勿转载和采集!