From the course: Debugging in C++ with Visual Studio Code
Unlock this course with a free trial
Join today to access over 24,700 courses taught by industry experts.
Solution: Debug with a knife in the woods - Visual Studio Code Tutorial
From the course: Debugging in C++ with Visual Studio Code
Solution: Debug with a knife in the woods
- [Instructor] For this challenge, we have a function that is supposed to calculate the average of the values in the vector sent as an argument in the test code area at the bottom right. However, there is something wrong with this function. We were asked to add print statements to expose the problem without using a debugger. So for this challenge, CoderPath is ideal. First, let's see how this program fails. As you can see in the console output at the left, the return value is 5.4, which doesn't look at all as the expected average. Look at the test vector at the bottom right, the smallest value there is 10. So the average should be at least 10. As requested, let me add a print statement in line 16 as a last step inside the loop. That should print the sum so far for each iteration as cumulative value after adding each of the five elements in the test vector. So as the loop progresses, those five values should either stay the same or go up, but they must never drop. Let's run it again…