From the course: Debugging in C#
Unlock the full course today
Join today to access over 24,700 courses taught by industry experts.
Solution: Discount calculator
From the course: Debugging in C#
Solution: Discount calculator
(upbeat music) - [Instructor] Let's fix the bug in the discount calculator. In the code, we calculate the discount amount and then subtract it from the original price. Let's use a print statement to find out what the discount percentage is once divided by 100. (typing) We'll also change the expected result variable to true, so we can see how what we get differs from what we expect. Let's run it. (silence) It looks like the discount percentage is resulting in zero when it should result in 0.9. This is likely due to the fact that the discount percentage is an integer, and 100 is an integer. This means that integer division will take place, making the result zero instead of 0.9. Let's add a decimal to the 100 so that decimal division takes place. (typing) Let's run the code again. (silence) Now the division discount is 0.9 or 90%, and our code returned the correct answer. Let's try with another input. We'll make the discount zero. (silence) We'll run it again. (silence) With our fix, the…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.