aboutsummaryrefslogtreecommitdiff
path: root/CST116-Ch7-Debugging/CST116-Ch7-Debugging-Florea.cpp
diff options
context:
space:
mode:
authorAndrei F <[email protected]>2022-10-12 21:56:11 -0700
committerAndrei F <[email protected]>2022-10-12 21:56:11 -0700
commitdf92b88a15e2fdfe9f9c1a00be2460ca26ac1b3b (patch)
tree439de9c59ff476c9a6e50d0938496ef1b3ba02c7 /CST116-Ch7-Debugging/CST116-Ch7-Debugging-Florea.cpp
parentFinished exercise 3 (diff)
downloadcst116-ch7-debugging-florea-df92b88a15e2fdfe9f9c1a00be2460ca26ac1b3b.tar.xz
cst116-ch7-debugging-florea-df92b88a15e2fdfe9f9c1a00be2460ca26ac1b3b.zip
Added output file and renamed the main file to include my name
Diffstat (limited to 'CST116-Ch7-Debugging/CST116-Ch7-Debugging-Florea.cpp')
-rw-r--r--CST116-Ch7-Debugging/CST116-Ch7-Debugging-Florea.cpp102
1 files changed, 102 insertions, 0 deletions
diff --git a/CST116-Ch7-Debugging/CST116-Ch7-Debugging-Florea.cpp b/CST116-Ch7-Debugging/CST116-Ch7-Debugging-Florea.cpp
new file mode 100644
index 0000000..bb7ed08
--- /dev/null
+++ b/CST116-Ch7-Debugging/CST116-Ch7-Debugging-Florea.cpp
@@ -0,0 +1,102 @@
+/********************************************************************
+* 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.
+ *
+ * Done, the age value is set to my input which is 19.
+ *
+* 5) Step over the if statement.
+* 6) Why did the value in age change?
+ *
+ * The value of age changed because the if comparison were not correctly written, there was only a single = sign,
+ * which means that it would assign a value to a variable. Additionally, the brackets to the if statements were
+ * missing and I added them.
+ *
+* 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?
+ *
+ * The problem is that on the first else if statement, it was using the OR ( || ) comparison, and that means that
+ * any input age is going to be more than 12 OR less than or equal to 19, therefore any age input is going to result
+ * in teenager.
+ *
+* 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?
+ *
+ * The action code inside the else block is executing because of the semicolon on the end of the "else",
+ * while I don't know why, I am assuming its because the ( compiler ? ) is assuming it's the end of a line and its
+ * automatically entering the block. Removing that semicolon will ensure that it won't execute.
+ *
+* 6) Fix the problem and re-run to verify the problem was corrected.
+ *
+ * If I input the age 19 now, it will correctly output Teenager.
+ *
+********************************************************************/
+
+#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