From f9196f7506c7a92407c3540cd3fbb62edd80b417 Mon Sep 17 00:00:00 2001 From: CEOofOogaBooga Date: Wed, 12 Oct 2022 11:00:20 -0700 Subject: CH7 Finished --- CST116-Ch7-Debugging/CST116-Ch7-Debugging.cpp | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'CST116-Ch7-Debugging/CST116-Ch7-Debugging.cpp') diff --git a/CST116-Ch7-Debugging/CST116-Ch7-Debugging.cpp b/CST116-Ch7-Debugging/CST116-Ch7-Debugging.cpp index f64adfe..a337a4c 100644 --- a/CST116-Ch7-Debugging/CST116-Ch7-Debugging.cpp +++ b/CST116-Ch7-Debugging/CST116-Ch7-Debugging.cpp @@ -12,7 +12,8 @@ * 4) When the execution stops, add a watch on age and verify that * the value in age is what you typed in. * 5) Step over the if statement. -* 6) Why did the value in age change? +* 6) Why did the value in age change? Because we entered age is = to 1 instead of ==. + = assigns things while == checks the number/value given from eariler. * 7) Fix the problem and repeat Steps 2 – 5 to verify the * problem was corrected. * 8) Stop debugging. @@ -26,6 +27,8 @@ * 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? +* This is because the program is reading that anything higher than 12 +* seperately from the program reading anything that is lower than 19. * 7) Fix the problem and repeat Steps 1 – 5 to verify the * problem was corrected. * 8) Stop debugging. @@ -36,6 +39,8 @@ * 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"? +* This is because there is a ; at the end of else with nothing before it so it is just there + and the program automatically reads the "adult" line because there isn't something stopping it. * 4) Re-run the program this time with debugging and run to * Breakpoint 2. * 5) Why is the action with the else executing? @@ -56,9 +61,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 (19 >= age && 12 <= age) cout << "Teenager" << endl; else if (age < 12) cout << "Child" << endl; @@ -66,7 +71,7 @@ int main() cout << "Senior" << endl; // Breakpoint 2 // Put a breakpoint on the following line - else; + else cout << "Adult" << endl; return 0; -- cgit v1.2.3