From f31155764281276463dca9964a68875964dfe432 Mon Sep 17 00:00:00 2001 From: Bold Demchig Date: Wed, 12 Oct 2022 20:54:16 -0700 Subject: Hi. I have completed my Ch7 debugging and pushed to GitHub. I have been trying to push it couple times already. --- CST116-Ch7-Debugging/CST116-Ch7-Debugging.cpp | 97 ++++++++++++++------------- 1 file changed, 51 insertions(+), 46 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..7c50bd8 100644 --- a/CST116-Ch7-Debugging/CST116-Ch7-Debugging.cpp +++ b/CST116-Ch7-Debugging/CST116-Ch7-Debugging.cpp @@ -6,68 +6,73 @@ * * Debugging Exercise 1 * -* 1) Insert a breakpoint on the lines indicated in the code. -* 2) Run to Breakpoint 1. -* 3) When prompted, enter your age. -* 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? +* 1) Insert a breakpoint on the lines indicated in the code. Done +* 2) Run to Breakpoint 1. Done +* 3) When prompted, enter your age. Done +* 4) When the execution stops, add a watch on age and verify that Done +* the value in age is what you typed in. Yes. It is correct. +* 5) Step over the if statement. Done +* 6) Why did the value in age change? No. It should not change. +* * 7) Fix the problem and repeat Steps 2 – 5 to verify the -* problem was corrected. -* 8) Stop debugging. +* problem was corrected. Problem solved and commented at the spot +* 8) Stop debugging. Done * * Debugging Exercise 2 * -* 1) Run to Breakpoint 1. -* 2) When prompted, enter the value 25 for your age. +* 1) Run to Breakpoint 1. Done +* 2) When prompted, enter the value 25 for your age. Done * 3) Step over the if statement. Execution of the program should -* continue on the else if statement. -* 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? -* 7) Fix the problem and repeat Steps 1 – 5 to verify the +* continue on the else if statement. Yes. It does. +* 4) Verify that 25 is still stored in age. Yes. It is stored +* 5) Step over the else if. Done +* 6) Why is the program going to print "Teenager" for an age of 25? Because it used OR instead of AND. +* The both of conditions should be satisfied. +* So, I changed || into &&. +* 7) Fix the problem and repeat Steps 1 – 5 to verify the Done * problem was corrected. -* 8) Stop debugging. -* 9) Remove Breakpoint1. +* 8) Stop debugging. Done +* 9) Remove Breakpoint1. Done * * Debugging Exercise 3 * -* 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"? -* 4) Re-run the program this time with debugging and run to -* Breakpoint 2. -* 5) Why is the action with the else executing? -* 6) Fix the problem and re-run to verify the problem was corrected. -********************************************************************/ +* 1) Run the program without debugging. Yes, I did +* 2) When prompted, enter the value of 10 for your age. Yes, I did +* 3) Why does the program print both "Child" and "Adult"? Because of ; after else +* 4) Re-run the program this time with debugging and run to +* Breakpoint 2. Done +* 5) Why is the action with the else executing? ; means the end of the line and it stops right there. +* +* 6) Fix the problem and re-run to verify the problem was corrected. Done +*/ #include + using std::cout; using std::endl; using std::cin; -int main() -{ - int age = 0; +int main() { + + int age = 0; - cout << "Enter your age: "; - cin >> age; + cout << "Enter your age: " <> age; - // Breakpoint 1 - // Put a breakpoint on the following line - if (age = 1) - cout << "First Birthday" << endl; - else if (age >= 12 || age <= 19) + // Breakpoint 1 + // Put a breakpoint on the following line + if (age == 1) // In C++, == means equal, so I corrected it. + cout << "First Birthday" << endl; + else if (age >= 12 && age <= 19) // && should be used here not || cout << "Teenager" << endl; - else if (age < 12) - cout << "Child" << endl; - else if (age > 62) - cout << "Senior" << endl; - // Breakpoint 2 - // Put a breakpoint on the following line - else; - cout << "Adult" << endl; + else if (age < 12 && age > 1) + cout << "Child" << endl; + else if (age >= 62 ) + cout << "Senior" << endl; + // Breakpoint 2 + // Put a breakpoint on the following line + else + cout << "Adult" << endl; - return 0; -} \ No newline at end of file + return 0; + } -- cgit v1.2.3