aboutsummaryrefslogtreecommitdiff
path: root/CST116-Ch7-Debugging/CST116-Ch7-Debugging-Williams.cpp
diff options
context:
space:
mode:
authorJoseph Williams <[email protected]>2022-10-05 16:35:29 -0700
committerJoseph Williams <[email protected]>2022-10-05 16:35:29 -0700
commit181de10a9a15c6fe3ac564bea16fa59b25669b72 (patch)
tree6977f97616a90a8d24f3d6a1766781181b4b5503 /CST116-Ch7-Debugging/CST116-Ch7-Debugging-Williams.cpp
parentSetting up GitHub Classroom Feedback (diff)
downloadcst116-ch7-debugging-allthenamesaretaken3141-181de10a9a15c6fe3ac564bea16fa59b25669b72.tar.xz
cst116-ch7-debugging-allthenamesaretaken3141-181de10a9a15c6fe3ac564bea16fa59b25669b72.zip
completed debugging problems, still need to add run file
Diffstat (limited to 'CST116-Ch7-Debugging/CST116-Ch7-Debugging-Williams.cpp')
-rw-r--r--CST116-Ch7-Debugging/CST116-Ch7-Debugging-Williams.cpp79
1 files changed, 79 insertions, 0 deletions
diff --git a/CST116-Ch7-Debugging/CST116-Ch7-Debugging-Williams.cpp b/CST116-Ch7-Debugging/CST116-Ch7-Debugging-Williams.cpp
new file mode 100644
index 0000000..2a717ff
--- /dev/null
+++ b/CST116-Ch7-Debugging/CST116-Ch7-Debugging-Williams.cpp
@@ -0,0 +1,79 @@
+// ANSWERS:
+// 1.6) The if statement uses =, instead of ==. == checks if two values are equal. = sets the first value to the second value.
+// 2.6) The if statement for "teenager" uses ||, instead of &&. || is an OR operator and returns true if one or both conditions are true. && is an AND operator and returns true only if both conditions are true.
+// 3.3) The cout statement that prints "Adult" isn't actually in the else statement, so it runs no matter what.
+// 3.5) Because it's not actually in the else statement.
+
+/********************************************************************
+* File: CST116-Ch7-Debugging.cpp
+*
+* General Instructions: Complete each step before proceeding to the
+* next.
+*
+* 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?
+* 7) Fix the problem and repeat Steps 2 � 5 to verify the
+* problem was corrected.
+* 8) Stop debugging.
+*
+* Debugging Exercise 2
+*
+* 1) Run to Breakpoint 1.
+* 2) When prompted, enter the value 25 for your age.
+* 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
+* problem was corrected.
+* 8) Stop debugging.
+* 9) Remove Breakpoint1.
+*
+* 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.
+********************************************************************/
+
+#include <iostream>
+using std::cout;
+using std::endl;
+using std::cin;
+
+int main()
+{
+ int age = 0;
+
+ cout << "Enter your age: ";
+ cin >> age;
+
+ // Breakpoint 1
+ // Put a breakpoint on the following line
+ 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)
+ cout << "Senior" << endl;
+ // Breakpoint 2
+ // Put a breakpoint on the following line
+ else
+ cout << "Adult" << endl;
+
+ return 0;
+} \ No newline at end of file