From 5e4b060bda36e689369ee6497b0f57315f45b396 Mon Sep 17 00:00:00 2001 From: Wyatt Date: Fri, 2 Dec 2022 11:41:42 -0800 Subject: assignment done --- CST116-Ch7-Debugging/CST116-Ch7-Debugging.cpp | 12 ++++++++---- cst116-ch7-debugging-johnson-Psuedocode.txt | 11 +++++++++++ cst116-ch7-debugging-johnson-output.txt | 6 ++++++ 3 files changed, 25 insertions(+), 4 deletions(-) create mode 100644 cst116-ch7-debugging-johnson-Psuedocode.txt create mode 100644 cst116-ch7-debugging-johnson-output.txt diff --git a/CST116-Ch7-Debugging/CST116-Ch7-Debugging.cpp b/CST116-Ch7-Debugging/CST116-Ch7-Debugging.cpp index f64adfe..f024491 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? +* the if statement has an assignment for age. It isnt checking if age equals 1, it is setting age to 1. * 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? +* age >= 12 is true when age is 25, the or statement doesnt check further and outputs Teenager. * 7) Fix the problem and repeat Steps 1 – 5 to verify the * problem was corrected. * 8) Stop debugging. @@ -36,9 +38,11 @@ * 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"? +* the else had a semicolon, which ended the statement. * 4) Re-run the program this time with debugging and run to * Breakpoint 2. * 5) Why is the action with the else executing? +* it wasnt inside the else. * 6) Fix the problem and re-run to verify the problem was corrected. ********************************************************************/ @@ -56,9 +60,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 +70,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 diff --git a/cst116-ch7-debugging-johnson-Psuedocode.txt b/cst116-ch7-debugging-johnson-Psuedocode.txt new file mode 100644 index 0000000..cf01cbe --- /dev/null +++ b/cst116-ch7-debugging-johnson-Psuedocode.txt @@ -0,0 +1,11 @@ +age = 0; +ask user for age; +set age to user input; + +if age = 1, output first birthday, +else if age is between 12 and 19, output teenager, +else if age is less than 12, output child, +else if age is greater than 62, output senior, +else output adult. + +return 0 \ No newline at end of file diff --git a/cst116-ch7-debugging-johnson-output.txt b/cst116-ch7-debugging-johnson-output.txt new file mode 100644 index 0000000..20fd565 --- /dev/null +++ b/cst116-ch7-debugging-johnson-output.txt @@ -0,0 +1,6 @@ +Enter your age: 25 +Adult + +C:\Users\wythe\Desktop\Homework\C++\cst116-ch7-debugging-johnson\CST116-Ch7-Debugging\x64\Debug\CST116-Ch7-Debugging.exe (process 2912) exited with code 0. +To automatically close the console when debugging stops, enable Tools->Options->Debugging->Automatically close the console when debugging stops. +Press any key to close this window . . . -- cgit v1.2.3