From 374039bfe6cfeb055899e83c6ed0cbd3e8f9c7a4 Mon Sep 17 00:00:00 2001 From: Andrei F Date: Wed, 12 Oct 2022 22:29:17 -0700 Subject: Finished exercise 4 --- CST116-Ch8-Debugging/CST116-Ch8-Debugging.cpp | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) (limited to 'CST116-Ch8-Debugging/CST116-Ch8-Debugging.cpp') diff --git a/CST116-Ch8-Debugging/CST116-Ch8-Debugging.cpp b/CST116-Ch8-Debugging/CST116-Ch8-Debugging.cpp index eaa348e..2cb243c 100644 --- a/CST116-Ch8-Debugging/CST116-Ch8-Debugging.cpp +++ b/CST116-Ch8-Debugging/CST116-Ch8-Debugging.cpp @@ -70,8 +70,23 @@ * 3) Verify that the contents of count is garbage. * 4) Step into the loop. * 5) What is the value stored in count now? + * + * The value stored in count before was 1, but after stepping into the loop the value stored is now 10 + * * 6) Where was 10 assigned to count? + * + * I believe the 10 was assigned to count on line 99, where basically it just did a loop on that line without entering + * the line below, and it did it until count was equal to 10. + * * 7) Fix the problem and re-run to verify. + * + * I fixed the problem, which was the same as the other loop with the semicolon on the for loop. + * I know the problem is fixed as I used the debugging tool and followed the flow of the code, entering + * the for loop until count was 10 + * + * I am also adding curly brackets (which are not necessary as I found out) but it makes the code cleaner + * and easier to read. + * ********************************************************************/ #include using std::cout; @@ -84,14 +99,16 @@ int main() // Breakpoint 1 // Put a breakpoint on the following line - while (i < 10) - cout << i++ << endl; + while (i < 10) { + cout << i++ << endl; + } // Breakpoint 2 // Put a breakpoint on the following line - for (count = 0; count < 10; count++); - cout << count << endl; + for (count = 0; count < 10; count++) { + cout << count << endl; + } return 0; } -- cgit v1.2.3