diff options
Diffstat (limited to 'CST116-Ch7-Debugging')
| -rw-r--r-- | CST116-Ch7-Debugging/CST116-Ch7-Debugging-Chambers.cpp | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/CST116-Ch7-Debugging/CST116-Ch7-Debugging-Chambers.cpp b/CST116-Ch7-Debugging/CST116-Ch7-Debugging-Chambers.cpp index 2cd1c90..eb350f8 100644 --- a/CST116-Ch7-Debugging/CST116-Ch7-Debugging-Chambers.cpp +++ b/CST116-Ch7-Debugging/CST116-Ch7-Debugging-Chambers.cpp @@ -13,6 +13,8 @@ * the value in age is what you typed in. * 5) Step over the if statement. * 6) Why did the value in age change? +* The value changed because instead of checking our value against the value of "First Birthday", +* with just one set of =, the instead set our age to 1. * 7) Fix the problem and repeat Steps 2 � 5 to verify the * problem was corrected. * 8) Stop debugging. @@ -26,6 +28,7 @@ * 4) Verify that 25 is still stored in age. * 5) Step over the else if. * 6) Why is the program going to print "Teenager" for an age of 25? +* The problem was the breaks added to the line instead of a comma, cutting off the second parrt of the statement. * 7) Fix the problem and repeat Steps 1 � 5 to verify the * problem was corrected. * 8) Stop debugging. @@ -36,9 +39,13 @@ * 1) Run the program without debugging. * 2) When prompted, enter the value of 10 for your age. * 3) Why does the program print both "Child" and "Adult"? +* It printed both Teenager and Adult because there was a semicolon, terminating the line before the +* statement for adult, making 10 pass for both teenager and adult. * 4) Re-run the program this time with debugging and run to * Breakpoint 2. * 5) Why is the action with the else executing? +* Again, with the semicolon in the line, the our line is being terminated before we give it a value to watch for, +* meaning that it will print adult for the age of 10 as long as that semicolon remains. * 6) Fix the problem and re-run to verify the problem was corrected. ********************************************************************/ @@ -56,9 +63,9 @@ int main() // Breakpoint 1 // Put a breakpoint on the following line - if (age = 1) + if (age == 1) cout << "First Birthday" << endl; - else if (age >= 12 || age <= 19) + else if (age >= 12, age <= 19) cout << "Teenager" << endl; else if (age < 12) cout << "Child" << endl; @@ -66,7 +73,7 @@ int main() cout << "Senior" << endl; // Breakpoint 2 // Put a breakpoint on the following line - else; + else cout << "Adult" << endl; return 0; |