Question: Murach's C# 2015 Training & Reference: I need help with both Exercise 4-1. I figured out steps 1-4, but not understanding how to modify the

Murach's C# 2015 Training & Reference: I need help with both Exercise 4-1.

I figured out steps 1-4, but not understanding how to modify the code for 5 & 6.

Code is:

private void btnCalculate_Click(object sender, EventArgs e) { decimal subtotal = Convert.ToDecimal(txtSubtotal.Text); decimal discountPercent = .25m; decimal discountAmount = subtotal * discountPercent; decimal invoiceTotal = subtotal - discountAmount;

txtDiscountPercent.Text = discountPercent.ToString("p1"); txtDiscountAmount.Text = discountAmount.ToString("c"); txtTotal.Text = invoiceTotal.ToString("c");

txtSubtotal.Focus(); }

5. Modify the first statement in the btnCalculate_Click method so it uses the Parse method of the Decimal class instead of the ToDecimal method of the Convert Class. Then, test the application to verify that it still works the same.

6. Round the values that are stored in the discountAmount and invoiceTotal variables to two decimal places, and delete the formatting codes for the statements that covert these variables to strings. Then, test the application to make sure that only two decimal places are displayed for the discount amount and total.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!