C#函数的简单使用

c#函数
  1 using System;
  2 public class ATM
  3 {
  4     public static string UserName = "";
  5     public static string UserPwd = "";
  6     public static double Money = 0;
  7     public static double Money1 = 0;
  8     public static void Main()
  9     {
 10         
 11         Menu();
 12     }
 13     //主菜单
 14     public static void Menu()
 15     {
 16         Console.WriteLine("----------请选择菜单-----------");
 17         Console.WriteLine("1,\t注册");
 18         Console.WriteLine("2,\t登录");
 19         Console.WriteLine("3,\t退出");
 20         string menu01 = Console.ReadLine();//得到的字符串类型
 21         if(menu01 == "1")
 22         {
 23             Register();//注册页面
 24         }
 25         if(menu01 == "2")
 26         {
 27             Login();
 28         }
 29     }
 30     //注册
 31     public static void Register()
 32     {
 33         Console.WriteLine("------------------------------------");
 34         Console.WriteLine("请选输入注册信息");
 35         Console.WriteLine("------------------------------------");
 36         Console.WriteLine("注册信息:请输入用户名");
 37         UserName = Console.ReadLine();
 38         if (UserName == "")
 39         {
 40             Console.WriteLine("用户名不能为空,注册失败");
 41             Menu();
 42         }
 43         Console.WriteLine("注册信息:请输入密码");
 44         UserPwd = Console.ReadLine();
 45         Console.WriteLine("请再次输入密码");
 46         string p = Console.ReadLine();
 47         if (UserPwd == "" || p == "")
 48         {
 49             Console.WriteLine("密码不能为空,注册失败");
 50             Register();
 51         }
 52         if (UserPwd != p)
 53         {
 54             Console.WriteLine("两次输入的密码不一致,注册失败");
 55             Register();
 56         }
 57         if(UserName != null && UserPwd == p)
 58         {
 59             Console.WriteLine("注册成功");
 60             Smenu();
 61         }
 62     }
 63     //登录
 64     public static void Login()
 65     {
 66         Console.WriteLine("------------------------------------");
 67         Console.WriteLine("------------------------------------");
 68         Console.WriteLine("请输入用户名");
 69         UserName = Console.ReadLine();
 70         Console.WriteLine("请输入密码");
 71         UserPwd = Console.ReadLine();
 72         if (UserName == ""|| UserPwd == "")
 73         {
 74             Console.WriteLine("用户名或密码不能为空,请重新登录!");
 75             Login();
 76         }else
 77         {
 78             Console.WriteLine("登录成功");
 79             Smenu();
 80         }
 81     }
 82     //登录成功菜单
 83     public static void Smenu()
 84     {
 85         Console.WriteLine("------------------------------------");
 86         Console.WriteLine("----------欢迎使用银行业务----------");
 87         Console.WriteLine("------------------------------------");
 88         Console.WriteLine("1,\t查询");
 89         Console.WriteLine("2,\t存款");
 90         Console.WriteLine("3,\t取款");
 91         Console.WriteLine("4,\t利息查询");
 92         Console.WriteLine("5,\t退出");
 93         string s = Console.ReadLine();
 94         if (s == "1")
 95         {
 96             Query();
 97         }
 98         if (s == "2")
 99         {
100             Deposit();
101         }
102         if (s == "3")
103         {
104             TakeMoney();
105         }
106         if (s == "4")
107         {
108             Rate();
109         }
110     }
111     //查询
112     public static void Query()
113     {
114         Console.WriteLine("您的账户木有存款,请先存款!");
115         Smenu();
116     }
117     //存款
118     public static void Deposit()
119     {
120         Console.WriteLine("------------------------------------");
121         Console.WriteLine("----------存款业务----------");
122         Console.WriteLine("------------------------------------");
123         Console.WriteLine("1,\t定期");
124         Console.WriteLine("2,\t活期");
125         Console.WriteLine("3,\t投资");
126         Console.WriteLine("4,\t返回");
127         string d = Console.ReadLine();
128         if (d == "1")
129         {
130             DingQi();
131         }
132         if (d == "2")
133         {
134             HuoQi();
135         }
136         if (d == "3")
137         {
138             Ivest();
139         }
140         if (d == "4")
141         {
142             Smenu();
143         }
144     }
145     //定期
146     public static double DingQi()
147     {
148         Console.WriteLine("---------------------------------");
149         Console.WriteLine("-----------定期存款--------------");
150         Console.WriteLine("请输入存款期限,选择相应序号");
151         Console.WriteLine("1,\t三个月");
152         Console.WriteLine("2,\t六个月");
153         Console.WriteLine("3,\t一年");
154         Console.WriteLine("4,\t三年");
155         Console.WriteLine("5,\t五年");
156         string yeard = Console.ReadLine();
157         Console.WriteLine("请输入存款数,只接收100元面值的钞票,一次最多准许放入5000元钞票!");
158             Money1 = Convert.ToDouble(Console.ReadLine());
159             int m = (int)Money1;
160             if (m < 100)
161             {
162                 Console.WriteLine("请取走现金!,您放入的现金少于100,请重新存款!");
163                 DingQi();
164             }
165             if (m > 5000)
166             {
167                 Console.WriteLine("请取走现金!,您放入的现金大于5000,请重新存款!");
168                 DingQi();
169             }
170             if (yeard == "1")
171             {
172                 Console.WriteLine("您本次定期存款是"+m+"");
173                 Smenu();
174             }
175             if (yeard == "2")
176             {
177                 Console.WriteLine("您本次定期存款是"+m+"");
178                 Smenu();
179             }
180             if (yeard == "3")
181             {
182                 Console.WriteLine("您本次定期存款是"+m+"");
183                 Smenu();
184             }
185             if (yeard == "4")
186             {
187                 Console.WriteLine("您本次定期存款是"+m+"");
188                 Smenu();
189             }
190             if (yeard == "5")
191             {
192                 Console.WriteLine("您本次定期存款是"+m+"");
193                 Smenu();
194             }
195         Console.WriteLine("返回存款业务");
196                 Deposit();
197                 return (Money1);
198     }
199     //活期
200     public static double HuoQi()
201     {
202         Console.WriteLine("---------------------------------");
203         Console.WriteLine("-----------活期存款--------------");
204         Console.WriteLine("1,\t进行活期存款");
205         Console.WriteLine("2,\t返回存款业务");
206         string h = Console.ReadLine();
207         if (h == "1")
208         {
209             Console.WriteLine("请输入存款数,只接收100元面值的钞票");
210             Money = Convert.ToDouble(Console.ReadLine());
211             int m1 = (int)Money;
212             if (m1 < 100 || m1 > 5000)
213             {
214                 Console.WriteLine("请取走现金!,您放入的现金少于100或大于5000,请重新存款!");
215                 HuoQi();
216             }else
217             {
218                 Console.WriteLine("您本次活期存款是"+m1+"");
219                 Deposit();
220             }
221         }
222         if (h == "2")
223         {
224             Deposit();
225         }
226         return (Money);
227     }
228     //投资
229     public static void Ivest()
230     {
231         Console.WriteLine("------------------------------------");
232         Console.WriteLine("----------投资业务----------");
233         Console.WriteLine("------------------------------------");
234         Console.WriteLine("请选择投资年限");
235         Console.WriteLine("1,\t一年");
236         Console.WriteLine("2,\t三年");
237         Console.WriteLine("3,\t五年");
238         Console.WriteLine("4,\t十年");
239         Console.WriteLine("5,\t返回主菜单");
240         string i = Console.ReadLine();
241         double iv = (Money+Money1);;
242         if ((Money+Money1) < 100000)
243         {
244             Console.WriteLine("最低投资额为10万元,您的存款不足,请先存款!");
245             Smenu();
246         }
247         if (i == "1")
248         {
249             double t1 = iv*0.05;
250             Console.WriteLine("一年的投资利息为"+t1+"");
251             Console.WriteLine("您本次投资了"+iv+"");
252         }
253         if (i == "2")
254         {
255             double t2 = iv*0.05*3;
256             Console.WriteLine("三年的投资利息为"+t2+"");
257             Console.WriteLine("您本次投资了"+iv+"");
258         }
259         if (i == "3")
260         {
261             double t3 = iv*0.05*5;
262             Console.WriteLine("五年的投资利息为"+t3+"");
263             Console.WriteLine("您本次投资了"+iv+"");
264         }
265         if (i == "4")
266         {
267             double t4 = iv*0.05*10;
268             Console.WriteLine("十年的投资利息为"+t4+"");
269             Console.WriteLine("您本次投资了"+iv+"");
270         }
271         if (i == "5")
272         {
273             Deposit();
274         }
275     }
276     //取款
277     public static void TakeMoney()
278     {
279         Console.WriteLine("------------------------------------");
280         Console.WriteLine("----------取款业务----------");
281         Console.WriteLine("------------------------------------");
282         Console.WriteLine("请选择取款数额,每日最高可取2万元,定期取款请到柜台办理!");
283         Console.WriteLine("1,\t100");
284         Console.WriteLine("2,\t200");
285         Console.WriteLine("3,\t500");
286         Console.WriteLine("4,\t1000");
287         Console.WriteLine("5,\t2000");
288         Console.WriteLine("6,\t3000");
289         Console.WriteLine("7,\t5000");
290         Console.WriteLine("8,\t返回菜单");
291         string t = Console.ReadLine();
292         if (Money < 100.00)
293         {
294             Console.WriteLine("您的余额不足!");
295         }
296         if (t == "1")
297         {
298             if (Money > 100)
299             {
300                 Console.WriteLine("您本次取款是100元");
301                 Money = Money-100;
302                 Smenu();
303             }
304         }
305         if (t == "2")
306         {
307             if (Money > 200)
308             {
309                 Console.WriteLine("您本次取款是200元");
310                 Money = Money-200;
311                 Smenu();
312             }else
313             {
314                 Console.WriteLine("您的余额不足!");
315                 Smenu();
316             }
317         }
318         if (t == "3")
319         {
320             if (Money > 500)
321             {
322                 Console.WriteLine("您本次取款是500元");
323                 Money = Money-500;
324                 Smenu();
325             }else
326             {
327                 Console.WriteLine("您的余额不足!");
328                 Smenu();
329             }
330         }
331         if (t == "4")
332         {
333             if (Money > 1000)
334             {
335                 Console.WriteLine("您本次取款是1000元");
336                 Money = Money-1000;
337                 Smenu();
338             }else
339             {
340                 Console.WriteLine("您的余额不足!");
341                 Smenu();
342             }
343         }
344         if (t == "5")
345         {
346             if (Money > 2000)
347             {
348                 Console.WriteLine("您本次取款是2000元");
349                 Money = Money-2000;
350                 Smenu();
351             }else
352             {
353                 Console.WriteLine("您的余额不足!");
354                 Smenu();
355             }
356         }
357         if (t == "6")
358         {
359             if (Money > 3000)
360             {
361                 Console.WriteLine("您本次取款是3000元");
362                 Money = Money-3000;
363                 Smenu();
364             }else
365             {
366                 Console.WriteLine("您的余额不足!");
367                 Smenu();
368             }
369         }
370         if (t == "7")
371         {
372             if (Money > 5000)
373             {
374                 Console.WriteLine("您本次取款是5000元");
375                 Money = Money-5000;
376                 Smenu();
377             }else
378             {
379                 Console.WriteLine("您的余额不足!");
380                 Smenu();
381             }
382         }
383         if (t == "8")
384         {
385             Console.WriteLine("返回菜单");
386             Smenu();    
387         }
388     }
389     //利息查询
390     public static void Rate()
391     {
392         Console.WriteLine("------------------------------------");
393         Console.WriteLine("----------利息查询业务----------");
394         Console.WriteLine("------------------------------------");
395         Console.WriteLine("请选择存款年限");
396         Console.WriteLine("1,\t三个月");
397         Console.WriteLine("2,\t六个月");
398         Console.WriteLine("3,\t一年");
399         Console.WriteLine("4,\t三年");
400         Console.WriteLine("5,\t五年");
401         Console.WriteLine("6,\t返回存款业务");
402         string r = Console.ReadLine();
403         if (r == "1")
404         {
405             double l1 = Money1*0.0285/12*3;
406             Console.WriteLine("三个月的利息为"+l1+"");
407             Smenu();
408         }
409         if (r == "2")
410         {
411             double l2 = Money1*0.0285/12*6;
412             Console.WriteLine("六个月的利息为"+l2+"");
413             Smenu();
414         }
415         if (r == "3")
416         {
417             double l3 = Money1*0.0285;
418             Console.WriteLine("一年的利息为"+l3+"");
419             Smenu();
420         }
421         if (r == "4")
422         {
423             double l4 = Money1*0.0285*3;
424             Console.WriteLine("三年的利息为"+l4+"");
425             Smenu();
426         }
427         if (r == "5")
428         {
429             double l5 = Money1*0.0285*5;
430             Console.WriteLine("五年的利息为"+l5+"");
431             Smenu();
432         }
433         if (r == "6")
434         {
435             Smenu();
436         }
437     }
438 }

这是函数调用的小练习,模仿ATM机。

posted @ 2012-07-30 18:36  何小盒  阅读(192)  评论(0编辑  收藏  举报