C#学费折扣如何计算折扣

时间:2015-09-19 08:52:54

标签: c#

如果学费为: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();

1 个答案:

答案 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();