Hi there: I am using C# coding, and visual studio 2012 I don\'t know why this co
ID: 671145 • Letter: H
Question
Hi there:
I am using C# coding, and visual studio 2012
I don't know why this code doesn't work?
I hope I get help with it, thnx
private void totalButton_Click(object sender, EventArgs e)
{
decimal foodChargeAmount; // The amount of food charge.
decimal tipPercentage, tipAmount; // The tip percentage & amount.
decimal saleTaxPercentage, saleTaxAmount; // Sale tax percentage & amount.
decimal totalAmount; // The total amount.
// Assigning food charge amount from TextBox control to respective variable.
foodChargeAmount = decimal.Parse(foodChargeTextBox.Text);
// We will assign the tip percentage as 15.
tipPercentage = 15;
// Tip amount calculation.
tipAmount = tipPercentage * (foodChargeAmount / 100);
// Assigning sales tax percentage as 7.
saleTaxPercentage = 7;
// Sales tax percentage calculation.
saleTaxAmount = saleTaxPercentage * (foodChargeAmount / 100);
// Total amount calculation.
totalAmount = (foodChargeAmount + tipAmount + saleTaxAmount);
resultLabel.BorderStyle = BorderStyle.FixedSingle;
resultLabel.ForeColor = Color.Tomato;
// The result label will display (Food charge + tip percentage + sale tax percentage + total amount).
resultLabel.Text = "Food Charge for a meal is:" +
foodChargeAmount.ToString("c") + "";
resultLabel.Text = "The tip percent for a meal is:" +
tipAmount.ToString("c") + "";
resultLabel.Text = "Sales tax percentage for a meal is:" +
saleTaxAmount.ToString("c") + "";
resultLabel.Text = "The total amount is"+
totalAmount.ToString("c") + "";
}
}
}
Explanation / Answer
Solution:
you need to display (Food charge + tip percentage + sale tax percentage + total amount using result label.
So combine all these answers as single string and assign that string value to the result label text.
Modified program:
private void totalButton_Click(object sender, EventArgs e)
{
decimal foodChargeAmount; // The amount of food charge.
decimal tipPercentage, tipAmount; // The tip percentage & amount.
decimal saleTaxPercentage, saleTaxAmount; // Sale tax percentage & amount.
decimal totalAmount; // The total amount.
// Assigning food charge amount from TextBox control to respective variable.
foodChargeAmount = decimal.Parse(foodChargeTextBox.Text);
// We will assign the tip percentage as 15.
tipPercentage = 15;
// Tip amount calculation.
tipAmount = tipPercentage * (foodChargeAmount / 100);
// Assigning sales tax percentage as 7.
saleTaxPercentage = 7;
// Sales tax percentage calculation.
saleTaxAmount = saleTaxPercentage * (foodChargeAmount / 100);
// Total amount calculation.
totalAmount = (foodChargeAmount + tipAmount + saleTaxAmount);
resultLabel.BorderStyle = BorderStyle.FixedSingle;
resultLabel.ForeColor = Color.Tomato;
// The result label will display (Food charge + tip percentage + sale tax percentage + total amount).
String answer="Food Charge for a meal is:"+foodChargeAmount.ToString("c") + ".The tip percent for a meal is:" +
tipAmount.ToString("c") + ". Sales tax percentage for a meal is:" + saleTaxAmount.ToString("c") + ". The total amount is"+
totalAmount.ToString("c") + "";
resultLabel.Text =answer;
}
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.