C#制作一个打印购物小票

求解... 求解 展开
 我来答
薯片奥利奥
2014-06-04 · TA获得超过251个赞
知道小有建树答主
回答量:78
采纳率:100%
帮助的人:82万
展开全部
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace PrintBill
{
    class Program
    {
        int ItemId;
        int Amount;
        int nongfushanquan = 0;
        int jinmailang = 0;
        int shuanghuihuotuichang = 0;
        string s = string.Empty;

        private void business()
        {
            Console.Write("输入商品编号:");
            ItemId = Convert.ToInt32(Console.ReadLine());
            Console.Write("输入商品数量:");
            Amount = Convert.ToInt32(Console.ReadLine());
            if (ItemId == 1)
            {
                nongfushanquan = nongfushanquan + Amount;
            }
            if (ItemId == 2)
            {
                jinmailang = jinmailang + Amount;
            }
            if (ItemId == 3)
            {
                shuanghuihuotuichang = shuanghuihuotuichang + Amount;
            }
            Console.WriteLine("输入e停止购物,输入其他任意键继续购物:");
             s = Console.ReadLine();
        }

        private void ProduceBill()
        {
            double sum1=0;
            double sum2=0;
            double sum3=0;

            Console.WriteLine("----------------欢迎光临光辉超市----------------");
                Console.WriteLine("商品名称        单价   数量   小计");
            if (nongfushanquan != 0)
            {
                sum1=nongfushanquan*1.02;
                Console.WriteLine("农夫山泉        1.02" +"   " + nongfushanquan + "      "  +"¥"+sum1);
            }
            if (jinmailang != 0)
            {
                sum2 = jinmailang * 3.5;
                Console.WriteLine("今麦郎碗面      3.50" + "   " + jinmailang + "      " + "¥" + sum2);
            }
            if (shuanghuihuotuichang != 0)
            {
                sum3 = shuanghuihuotuichang * 0.5;
                Console.WriteLine("双汇火腿肠      0.50" + "   " + shuanghuihuotuichang + "      " + "¥" + sum3);
            }

            double totalSum = sum1 + sum2 + sum3;
            Console.WriteLine("总计:¥"+totalSum);

        }

        static void Main(string[] args)
        {
            Console.WriteLine("编号   商品名称");
            Console.WriteLine("1      农夫山泉");
            Console.WriteLine("2      今麦郎碗面");
            Console.WriteLine("3      双汇火腿肠");
            Console.WriteLine(" ");
            Program p = new Program();
            p.business();
            while (p.s != "e")
            {
                p.business();
            }
            p.ProduceBill();
        }
    }
}

 运行结果:

建议你自己再写写。

玩转数据处理
推荐于2016-07-20 · 数据处理,Python,dotnet
玩转数据处理
采纳数:1613 获赞数:3794

向TA提问 私信TA
展开全部
//输出宽度自己调下吧

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.OleDb;
using System.Data;

namespace test
{
public class Goods
{
int number;
string name;
double price;
int buyCount;

public int Number
{
get { return this.number; }
set { this.number = value; }
}

public string Name
{
get { return this.name; }
set { this.name = value; }
}

public double Price
{
get { return this.price; }
set { this.price = value; }
}

public int BuyCount
{
get { return this.buyCount; }
set { this.buyCount = value; }
}
}

class Program
{
static void Main(string[] args)
{
Dictionary<int, string> initGoods = new Dictionary<int, string>();
initGoods.Add(1, "1;农夫山泉;2.50");
initGoods.Add(2, "2;今麦郎碗面;1.50");
initGoods.Add(3, "3;双汇火腿肠;1.00");
Dictionary<int, Goods> goodList = init(initGoods);//初始化商品
Console.WriteLine("编号 商品名称");
foreach (int item in goodList.Keys)
{
Console.Write(item);
Console.Write(" " + goodList[item].Name);
Console.WriteLine();
}
Console.WriteLine();
Dictionary<int, Goods> buyGoods = new Dictionary<int, Goods>();//购买商品
label1:
Console.Write("输入商品编号:");
int bianhao = Convert.ToInt32(Console.ReadLine());
if (!goodList.Keys.Contains(bianhao))
{
Console.WriteLine("不存在商品编号!");
Console.WriteLine();
goto label1;
}
if (!buyGoods.Keys.Contains(bianhao))
{
buyGoods.Add(bianhao, goodList[bianhao]);
}
Console.Write("输入购买数量:");
int buyGoodCount = Convert.ToInt32(Console.ReadLine());
buyGoods[bianhao].BuyCount += buyGoodCount;
Console.Write("输入e停止购物,输入其他任意键继续购物:");
string s = Console.ReadLine();
if (s.ToUpper() == "E")
{
goto print;
}
else
{
goto label1;
}
print:
Console.WriteLine();
Console.WriteLine("----------------欢迎光临光辉超市----------------");
Console.WriteLine("商品名称 单价 数量 小计");
foreach (int item in buyGoods.Keys)
{
Console.Write(buyGoods[item].Name);
Console.Write(" "+buyGoods[item].Price);
Console.Write(" " + buyGoods[item].BuyCount);
Console.Write(" ¥" + (buyGoods[item].Price * buyGoods[item].BuyCount));
Console.WriteLine();
}
Console.ReadKey();
}

private static Dictionary<int, Goods> init(Dictionary<int, string> goodsAndPrice)
{
Dictionary<int, Goods> goods = new Dictionary<int, Goods>();
Goods goodsSigle;
for (int i = 1; i <= goodsAndPrice.Count; i++)
{
goodsSigle = new Goods();
string[] temp = goodsAndPrice[i].ToString().Split(';');
goodsSigle.Number = Convert.ToInt32(temp[0]);
goodsSigle.Name = temp[1];
goodsSigle.Price = Convert.ToDouble(temp[2]);
goods.Add(goodsSigle.Number, goodsSigle);
}
return goods;
}
}
}
本回答被提问者采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
果冻我喜欢喜郎
2014-06-04
知道答主
回答量:40
采纳率:0%
帮助的人:17.3万
展开全部
这个其实还是很简单的,如果没有要求使用数据库,这个你就先用集合保存数据存在内存中
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 更多回答(1)
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式