C#实现银行存取款

       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("系统服务结束");

        }

  • 7
    点赞
  • 31
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 14
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 14
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

一叶知秋~

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值