简体   繁体   中英

C# Tuition Discount How to compute discount

Example if Tuition Fee is : 3000

Discount Percent in Cash : 20% Installment : 5%

Total : (here)

Code

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

Seperate the two discounts into seperate variables and compute to get the right results:

//Computation
var cashDiscount = tuition * (cash / 100); 
var installationDiscount = tuition * installment; 
discount = cashDiscount + installationDiscount;
total = tuition - discount; 

textBox5.Text = discount.ToString(); 
textBox3.Text = total.ToString();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM