与windows窗体应用程序中的收银机程序有关的问题



我正在创建一个收银机程序。这是一个简单的数学,其中的结果>金钱付出了代价。我想在文本框中打印出你们能拿回多少钱以及面额。例如,您输入price"500〃;并且成本";650〃>文本应该说";退款:150100美元50美元";。这是我第一次在windows窗体中编程,我已经用C#创建了程序,但无法在windows窗体上实现。我的代码看起来像这样。

public partial class Form1 : Form
{
int price, cost, tot, fivehundred, twohundred, onehundred, fifty, twenty;
private void txt_two_TextChanged(object sender, EventArgs e)
{
}
private void textBox3_TextChanged(object sender, EventArgs e)
{

}
public Form1()
{
InitializeComponent();
}
private void btn_add_Click(object sender, EventArgs e)
{
price = Convert.ToInt32(txt_one.Text);
cost = Convert.ToInt32(txt_two.Text);
tot = cost - price;
fivehundred = (cost - price) / (500);
fivehundred = fivehundred % 500;
twohundred = (cost - price) / 200;
twohundred = twohundred % 200;
onehundred = (cost - price) / 100;
onehundred = onehundred % 100;
fifty = (cost - price) / 50;
fifty = fifty % 50;
twenty = (cost - price) / 20;
twenty = twenty % 20;
textBox1.Text = Convert.ToString("Money back: " + Environment.NewLine + tot + " dollar " + Environment.NewLine + (fivehundred) + " fivehundred" + Environment.NewLine + (twohundred) + " twohundred" + Environment.NewLine + (onehundred) + " onehundred" + Environment.NewLine + (fifty) + " fifty" + Environment.NewLine + (twenty) + " twenty");
}
}

在此处输入图像描述

在此处输入图像描述

在计算出较小面额之前,您的算法不会从余数中减去最高面额,因此它实际上是在计算每行上的一种面额可以用多少种不同的方式来弥补总数。一旦你决定支付500,你就需要弄清楚如何支付500以上的剩余余额,而不是全部余额。

最新更新