您的位置:首页 > 其它

打印小票

2016-09-11 17:38 99 查看
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();
}
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: