diff options
| author | Andrei F <[email protected]> | 2022-10-12 22:29:17 -0700 |
|---|---|---|
| committer | Andrei F <[email protected]> | 2022-10-12 22:29:17 -0700 |
| commit | 374039bfe6cfeb055899e83c6ed0cbd3e8f9c7a4 (patch) | |
| tree | 900c823683687fcd1f7f13d48eae31061bf79bd8 /CST116-Ch8-Debugging/CST116-Ch8-Debugging.cpp | |
| parent | Finished exercise 3 (diff) | |
| download | cst116-chapter8-debugging-florea-374039bfe6cfeb055899e83c6ed0cbd3e8f9c7a4.tar.xz cst116-chapter8-debugging-florea-374039bfe6cfeb055899e83c6ed0cbd3e8f9c7a4.zip | |
Finished exercise 4
Diffstat (limited to 'CST116-Ch8-Debugging/CST116-Ch8-Debugging.cpp')
| -rw-r--r-- | CST116-Ch8-Debugging/CST116-Ch8-Debugging.cpp | 25 |
1 files changed, 21 insertions, 4 deletions
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 <iostream>
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;
}
|