From 6c1622282af965a4b7d32fd5f4da0909daca376b Mon Sep 17 00:00:00 2001 From: JonCr Date: Wed, 12 Oct 2022 18:22:38 -0700 Subject: Finished --- CST116-Ch7-Debugging/CST116-Ch7-Debugging.cpp | 11 +++++++---- 1 file changed, 7 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..a35b784 100644 --- a/CST116-Ch7-Debugging/CST116-Ch7-Debugging.cpp +++ b/CST116-Ch7-Debugging/CST116-Ch7-Debugging.cpp @@ -13,6 +13,7 @@ * the value in age is what you typed in. * 5) Step over the if statement. * 6) Why did the value in age change? +* A) The if statement set age equal to 1 instead. * 7) Fix the problem and repeat Steps 2 – 5 to verify the * problem was corrected. * 8) Stop debugging. @@ -26,6 +27,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? +* A) Because 25 is greater than 12, and an or operator was used instead of and. * 7) Fix the problem and repeat Steps 1 – 5 to verify the * problem was corrected. * 8) Stop debugging. @@ -39,6 +41,7 @@ * 4) Re-run the program this time with debugging and run to * Breakpoint 2. * 5) Why is the action with the else executing? +* A) A semicolon was placed after the "else," ending it early and letting the cout for "Adult" execute every time. * 6) Fix the problem and re-run to verify the problem was corrected. ********************************************************************/ @@ -56,9 +59,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,8 +69,8 @@ int main() cout << "Senior" << endl; // Breakpoint 2 // Put a breakpoint on the following line - else; - cout << "Adult" << endl; + else + cout << "Adult" << endl; return 0; } \ No newline at end of file -- cgit v1.2.3