文件名称:C#实验题目
文件大小:36KB
文件格式:DOC
更新时间:2016-10-29 10:50:21
C#
实验2using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Test2._1 { class MyException : Exception { public MyException(string message):base (message){ } public override string Message { get { return "Error"+base.Message; } } } class Program { static void Main(string[] args) { double coin = 0,m; string s, flag="y"; while (flag != "n") { Console.WriteLine("存款请输入“r”,取款请输入“d”:"); s = Console.ReadLine(); if (s == "r") { Console.WriteLine("请输入存款金额:"); m = double.Parse(Console.ReadLine()); coin = coin + m; Console.WriteLine("余额为:" + coin); } else { Console.WriteLine("请输入取款金额:"); m = double.Parse(Console.ReadLine()); try { coin = coin - m; if (coin < 0) { throw new MyException("余额不足!"); } } catch (MyException e) { Console.WriteLine(e.Message); } finally { if (coin < 0) { coin = coin + m; Console.WriteLine("余额为:" + coin); } else { Console.WriteLine("余额为:" + coin); } } } Console.WriteLine("继续业务请输入“y”,结束业务请输入“n”:"); flag = Console.ReadLine(); if (flag == "n") { Console.WriteLine("欢迎下次使用!谢谢"); } } } } }