From ea1bc343679954b82538659d12feb825780789cd Mon Sep 17 00:00:00 2001 From: Evan Date: Tue, 11 Oct 2022 20:03:59 -0700 Subject: anwsers --- CST116-Ch7-Debugging/CST116-Ch7-Debugging.cpp | 29 ++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 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..4b708dd 100644 --- a/CST116-Ch7-Debugging/CST116-Ch7-Debugging.cpp +++ b/CST116-Ch7-Debugging/CST116-Ch7-Debugging.cpp @@ -13,6 +13,9 @@ * the value in age is what you typed in. * 5) Step over the if statement. * 6) Why did the value in age change? +* +* the if statement is setting age value to 1 +* * 7) Fix the problem and repeat Steps 2 – 5 to verify the * problem was corrected. * 8) Stop debugging. @@ -26,6 +29,9 @@ * 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? +* +* because it is using || instead of && +* * 7) Fix the problem and repeat Steps 1 – 5 to verify the * problem was corrected. * 8) Stop debugging. @@ -36,16 +42,22 @@ * 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"? +* +* mine is working how it should +* * 4) Re-run the program this time with debugging and run to * Breakpoint 2. * 5) Why is the action with the else executing? +* +* mine is working how it should +* * 6) Fix the problem and re-run to verify the problem was corrected. ********************************************************************/ #include using std::cout; -using std::endl; using std::cin; +using std::endl; int main() { @@ -56,18 +68,21 @@ 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) - cout << "Teenager" << endl; + else if (age < 12) cout << "Child" << endl; - else if (age > 62) + + else if (age >= 12 && age <= 19) + cout << "Teenager" << endl; + + else if (age >= 62) 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