如果学费为:3000
现金折扣百分比:20% 分期付款:5%
总计:(此处)
代码
int tuition = 0;
double cash = 0.20;
double installment = 0.5;
double discount; double total;
tuition = int.Parse(textBox4.Text);
cash = double.Parse(textBox1.Text);
//Computation
discount = tuition * (cash / 100);
discount = tuition * installment;
total = tuition - discount;
textBox5.Text = discount.ToString();
textBox3.Text = total.ToString();
答案 0 :(得分:0)
将两个折扣分成单独的变量并进行计算以获得正确的结果:
//Computation
var cashDiscount = tuition * (cash / 100);
var installationDiscount = tuition * installment;
discount = cashDiscount + installationDiscount;
total = tuition - discount;
textBox5.Text = discount.ToString();
textBox3.Text = total.ToString();