aboutsummaryrefslogtreecommitdiff
path: root/main.cpp
diff options
context:
space:
mode:
authorlevidavis04 <[email protected]>2022-10-15 22:30:37 -0700
committerGitHub <[email protected]>2022-10-15 22:30:37 -0700
commitbd8450d0955242badc61895d58eebb65fd47c915 (patch)
tree91610cb50265d4f084ffdd0ca64d2a3bb0d869e8 /main.cpp
parentDelete main.cpp (diff)
downloadcst116-ch7-debugging-levidavis04-main.tar.xz
cst116-ch7-debugging-levidavis04-main.zip
Add files via uploadHEADmain
Diffstat (limited to 'main.cpp')
-rw-r--r--main.cpp76
1 files changed, 76 insertions, 0 deletions
diff --git a/main.cpp b/main.cpp
new file mode 100644
index 0000000..67e377d
--- /dev/null
+++ b/main.cpp
@@ -0,0 +1,76 @@
+//
+// main.cpp
+// CST116 Chapter 7 debugging exercises Davis
+//
+// Created by Levi on 10/12/22.
+//
+/********************************************************************
+* 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? because it says age = 1 not if age==1.
+* 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? because it is an 'or' statement so since it is > or = to 12 it thinks to print 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"? because, according to the code, it satisfies both variables
+* 4) Re-run the program this time with debugging and run to
+* Breakpoint 2.
+* 5) Why is the action with the else executing? because we need 'and' statements in the if statements
+* 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;
+
+ if (age == 1)
+ cout << "First Birthday" << endl;
+ else if (age < 12 && age > 1)
+ cout << "Child" << endl;
+ else if (age >= 12 && age <= 19)
+ cout << "Teenager" << endl;
+ else if (age > 62)
+ cout << "Senior" << endl;
+
+ else
+ cout << "Adult" << endl;
+
+ return 0;
+}