const readline = require('readline-sync');
//定义单账户名和密码,还有金额
let username1 = 'qzw';
let password1 = '123';
let money = 2000;
//saveMoney存钱
//drawMoney取钱
//定义次数
let count = 3;
//循环的状态
let state = true;
while (state) {
console.log('欢迎光临帅比银行');
console.log('请输入账号');
//接受用户输入
let inputname = readline.question();
//判断输入账户名等于定义账户名
if (inputname == username1) {
console.log('请输入密码');
let inputpwd = readline.question();
//判断输入密码等于定义的密码就登录成功
if (inputpwd == password1) {
console.log(`登陆成功!欢迎${inputname}`);
while (state) {
console.log(`请选择:1.查询余额2.存钱3.取钱0.退出系统`);
let option = readline.question() - 0;
switch (option) {
case 1:
console.log(`当前的余额为${money}元`);
break;
case 2:
console.log(`请输入存钱金额`);
let savemoney = readline.question() - 0;
money = money + savemoney;
console.log(`存钱成功!当前金额为${money}元`);
break;
case 3:
console.log('请输入取钱金额');
let drawmoney = readline.question() - 0;
if (drawmoney <= money) {
money = money - drawmoney;
console.log(`取钱成功!,当前余额为${money}元`);
} else
console.log('取钱失败,金额不足,请重新输入');
break;
case 0:
console.log('退出成功!欢迎下次光临');
state = false;
//跳出
break;
}
}
}
}
console.log('欢迎下次光临');
}
ATM机单账户版
最新推荐文章于 2024-08-30 16:13:36 发布