作业

去超市选择购买的商品

0.开始购买

1.洗发水15元

2.牙刷5元

3.可口可乐3元

4.水杯12元

5.毛巾6元

输入商品编号,输入每种要买几件;

结算:需要列出来商品名称,单价,数量,总价及所有商品总价,结账时间,输入交给收银员的钱数,不够继续交钱,够结账找钱。

  1  Console.WriteLine("0.开始购买");
  2             //Console.WriteLine("1.洗发水      15元");
  3             //Console.WriteLine("2.牙刷        5元");
  4             //Console.WriteLine("3.可口可乐    3元");
  5             //Console.WriteLine("4.水杯        12元");
  6             //Console.WriteLine("5.毛巾        6元");
  7             Console.WriteLine("6.结算(退出)");
  8 
  9             Console.Write("请输入号码:");
 10             for (int i = 0; i == 0; )
 11             {
 12                 int aa = int.Parse(Console.ReadLine());
 13                 if (aa == 0)
 14                 {
 15                     ArrayList al = new ArrayList();
 16                     int biao1 = 0;
 17                     for (int j = 0; j == 0; )
 18                     {
 19                         bool biaocuo = true;
 20                         string[] array = new string[3];
 21                         Console.Clear();
 22                         if (al.Count > 0)
 23                         {
 24                             for (int k = 0; k < al.Count; k++)
 25                             {
 26                                 string[] yigou = (string[])al[k];
 27                                 Console.WriteLine("您选择了{0},单价为{1}元,数量为{2}。", yigou[0], yigou[1], yigou[2]);
 28                             }
 29                         }
 30                         Console.WriteLine("1.洗发水      15元");
 31                         Console.WriteLine("2.牙刷        5元");
 32                         Console.WriteLine("3.可口可乐    3元");
 33                         Console.WriteLine("4.水杯        12元");
 34                         Console.WriteLine("5.毛巾        6元");
 35                         Console.WriteLine("6.结算");
 36 
 37                         Console.Write("请输入选项:");
 38                         int aaa = int.Parse(Console.ReadLine());
 39                         switch (aaa)
 40                         {
 41                             case 1:
 42                                 array[0] = "洗发水";
 43                                 array[1] = "15";
 44                                 biao1++;
 45                                 Console.Write("您选择的是洗发水,请问您需要多少瓶?");
 46                                 break;
 47                             case 2:
 48                                 array[0] = "牙刷";
 49                                 array[1] = "5";
 50                                 biao1++;
 51                                 Console.Write("您选择的是牙刷,请问您需要多少支?");
 52                                 break;
 53                             case 3:
 54                                 array[0] = "可口可乐";
 55                                 array[1] = "3";
 56                                 biao1++;
 57                                 Console.Write("您选择的是可口可乐,请问您需要多少瓶?");
 58                                 break;
 59                             case 4:
 60                                 array[0] = "水杯";
 61                                 array[1] = "12";
 62                                 biao1++;
 63                                 Console.Write("您选择的是水杯,请问您需要多少个?");
 64                                 break;
 65                             case 5:
 66                                 array[0] = "毛巾";
 67                                 array[1] = "6";
 68                                 biao1++;
 69                                 Console.Write("您选择的是毛巾,请问您需要多少块?");
 70                                 break;
 71                             case 6:
 72                                 if (biao1 == 0)
 73                                 {
 74                                     Console.Clear();
 75                                     Console.WriteLine("您什么也没有购买,您已经走出了超市。。。");
 76                                     j = 1;
 77                                     i = 1;
 78                                 }
 79                                 else
 80                                 {
 81                                     int zong = 0;
 82                                     for (int k = 0; k < al.Count; k++)
 83                                     {
 84                                         string[] yigou = (string[])al[k];
 85                                         Console.WriteLine("您选择了{0},单价为{1}元,数量为{2},单品总价:{3}。", yigou[0], yigou[1], yigou[2], (int.Parse(yigou[1]) * int.Parse(yigou[2])));
 86                                         zong += int.Parse(yigou[1]) * int.Parse(yigou[2]);
 87                                     }
 88                                     Console.Write("总价:" + zong + "元。请缴费:");
 89                                     int erjiao = 0;
 90                                     for (int l = 0; l == 0; )
 91                                     {
 92                                         int jiao = int.Parse(Console.ReadLine());
 93                                         jiao += erjiao;
 94                                         if (jiao >= zong)
 95                                         {
 96                                             Console.WriteLine("交易成功,交易时间为:" + DateTime.Now);
 97                                             Console.WriteLine("找零:" + (jiao - zong) + "元。");
 98                                             Console.WriteLine("谢谢惠顾!再见!");
 99                                             l = 1;
100                                             j = 1;
101                                             i = 1;
102                                         }
103                                         else
104                                         {
105                                             erjiao = jiao;
106                                             Console.Write("缴费金额不足,请继续缴费:");
107                                         }
108                                     }
109                                 }
110                                 break;
111                             default:
112                                 Console.WriteLine("查无此商品!请按回车键继续选择商品!");
113                                 Console.ReadLine();
114                                 biaocuo = false;
115                                 break;
116                         }
117                         if (i == 0 && j == 0 && biaocuo == true)
118                         {
119                             array[2] = Console.ReadLine();
120                             Console.WriteLine("您选择了{0},单价为{1}元,数量为{2}。请按回车键继续购买!", array[0], array[1], array[2]);
121                             al.Add(array);
122                             Console.ReadLine();
123                         }
124                     }
125                 }
126                 else if (aa == 6)
127                 {
128                     Console.Clear();
129                     Console.WriteLine("您什么也没有购买!您已走出超市。。。");
130                     i = 1;
131                 }
132                 else
133                 {
134                     Console.Write("输入有误!请重新输入:");
135                 }
136             } 
View Code

 

posted @ 2016-10-22 11:13  游称  阅读(154)  评论(0编辑  收藏  举报