打印小票

来源:互联网 发布:linux将utf8转换为gbk 编辑:程序博客网 时间:2024/04/30 07:31
using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;namespace Day04{    public class Show {        public string names;        public double prices;        Show[] shop = new Show[3];        public void Showinfo() {            shop[0] = new Show();            shop[0].names = "农夫山泉";            shop[0].prices = 1.03;            shop[1] = new Show();            shop[1].names = "今麦郎碗面";            shop[1].prices = 3.50;            shop[2] = new Show();            shop[2].names = "双汇火腿肠";            shop[2].prices = 12.60;            Console.WriteLine("编号\t商品名称\t单价");            for (int i = 0; i < shop.Length; i++) {                Console.WriteLine((i + 1) + "\t" + shop[i].names + "\t" + shop[i].prices);            }                }        public void Show1() {            int[] num = new int[30];            int[] num1 = new int[30];            string answer="";            do            {                Console.WriteLine();                for (int i = 0; i < num.Length; i++)                {                    Console.Write("请输入商品标号:");                    num[i] =int .Parse( Console.ReadLine());                    Console.Write("请输入数量:");                    num1[i] = int.Parse(Console.ReadLine());                    Console.Write("输入e停止购物,输入其他的任意键继续购物:");                    answer = Console.ReadLine();                    Console.WriteLine();                    if ("e".Equals(answer)) {                        break;                    }                }                break;            } while (!("e".Equals(answer)));            Console.WriteLine("===============欢迎光临光辉超市================");            Console.WriteLine("商品名称\t单价\t数量\t小计");            double sum = 0;            do            {                for (int i = 0; i < num.Length; i++)                {                    if (num[i] != 0) {                        Console.WriteLine(shop[num[i] - 1].names + "\t" + shop[num[i] - 1].prices + "\t" +  num1[i]+"\t"+num1[i]* shop[num[i] - 1].prices );                        sum = sum + num1[i] * shop[num[i] - 1].prices;                    }                }            } while (!("e".Equals(answer)));            Console.WriteLine();            Console.WriteLine("小计:"+sum);        }    }    class Program    {        static void Main(string[] args)        {            Show show = new Show();            show.Showinfo();            show.Show1();            Console.ReadLine();        }    }}

0 0
原创粉丝点击