static void Main(string[] args)
{
Console.WriteLine("********************************************************************");
Console.WriteLine("** **");
Console.WriteLine("** 欢迎光临湖北银行自动终端系统为您服务 **");
Console.WriteLine("** **");
Console.WriteLine("********************************************************************");
for (int a = 0; a < 3; a++)
{
Console.Write("账号:");
var name = Console.ReadLine();
Console.Write("密码:");
var pwd = Console.ReadLine();
if (name == "admin" && pwd == "123")//账号密码是否正确
{
Console.WriteLine("");
break;//正确则跳出循环进行下一步
}
Console.WriteLine("账号密码输入错误");
Console.WriteLine("");
if (a == 2)//从0开始0,1,2三次不正确
{
return;//返回,结束服务
}
}
string type = "";//服务类型
string start = "yes";//系统开关
string[] Record = new string[50];//存取款记录
int money = 0;//客户的余额
int i = 0;//计数
do
{
Console.WriteLine("");
Console.WriteLine("选择银行服务:");
Console.WriteLine("1.存款");
Console.WriteLine("2.取款");
Console.WriteLine("3.查询");
Console.WriteLine("4.退出");
type = Console.ReadLine();//选择服务项
if (type != "1" && type != "2" && type != "3" && type != "4")//判断是不是选择正确的操作
{
Console.WriteLine("操作错误,系统服务退出 Bye-Byg!");
break;
}
switch (type)
{
case "1":
Console.WriteLine("输入存款金额");
string price= Console.ReadLine();
int number;
if (!int.TryParse(price, out number))//判断输入的是不是数字
{
Console.WriteLine("金额输入错误!");
Console.WriteLine("存款操作已经取消!");
}
else
{
if (int.Parse(price)> 0)//判断输入金额是否大于0
{
money += int.Parse(price);
Record[i] =DateTime.Now.ToString("yy/MM/dd hh:mm:ss")+"存款"+ price;//写入存款记录
i++;
}
else
{
Console.WriteLine("金额为负数或为零!");
Console.WriteLine("存款操作已经取消!");
}
}
break;
case "2":
Console.WriteLine("输入取款金额");
string pricenew = Console.ReadLine();
int numbernew;
if (!int.TryParse(pricenew, out numbernew))//判断输入的是不是数字
{
Console.WriteLine("金额输入错误!");
Console.WriteLine("存款操作已经取消!");
}
else
{
if (int.Parse(pricenew) > 0)// 判断输入金额是否大于0
{
if ((money-int.Parse(pricenew))>=0)//判断剩余金额是否大于取款的金额
{
money -= int.Parse(pricenew);
Record[i] = DateTime.Now.ToString("yy/MM/dd hh:mm:ss") + "取款" + pricenew;//写入取款记录
i++;
} else
{
Console.WriteLine("余额不足!");
Console.WriteLine("存款操作已经取消!");
}
}
else
{
Console.WriteLine("金额为负数或为零!");
Console.WriteLine("存款操作已经取消!");
}
}
break;
case "3":
Console.WriteLine("----------------------------------------------------------------");
for (int j = 0; j <i; j++)
{
Console.WriteLine(Record[j]);//循环打印操作记录
}
Console.WriteLine("当前账户余额:{0}",money);
break;
case "4":
start= "no";
break;
}
} while (start=="yes");
Console.WriteLine("系统服务结束");
}
C#实现银行存取款
最新推荐文章于 2024-03-10 22:58:26 发布