diff options
| -rw-r--r-- | CST116-Ch7-Debugging/CST116 Ch7 pseudo code.txt | 10 | ||||
| -rw-r--r-- | CST116-Ch7-Debugging/CST116 Debugging Output.txt | 6 | ||||
| -rw-r--r-- | CST116-Ch7-Debugging/CST116-Ch7-Debugging.cpp | 13 |
3 files changed, 25 insertions, 4 deletions
diff --git a/CST116-Ch7-Debugging/CST116 Ch7 pseudo code.txt b/CST116-Ch7-Debugging/CST116 Ch7 pseudo code.txt new file mode 100644 index 0000000..51e49bd --- /dev/null +++ b/CST116-Ch7-Debugging/CST116 Ch7 pseudo code.txt @@ -0,0 +1,10 @@ +Under main +set and place age as 0 +output "Enter your age: " +input age +if age is equal to 1, output "First Birthday" +if age is less than 12, output "Child" +if age is greater than or equal to 12 +and less than or equal to 19, output "Teenager" +if age is greater than 62, output "Senior" +if age is outside those groups, output "Adult"
\ No newline at end of file diff --git a/CST116-Ch7-Debugging/CST116 Debugging Output.txt b/CST116-Ch7-Debugging/CST116 Debugging Output.txt new file mode 100644 index 0000000..51f3b91 --- /dev/null +++ b/CST116-Ch7-Debugging/CST116 Debugging Output.txt @@ -0,0 +1,6 @@ +Enter your age: 19 +Teenager + +C:\Users\furyf\OneDrive\Desktop\Homework\CST Homework\CST116 Chp7\CST116-Ch7-Debugging\x64\Debug\CST116-Ch7-Debugging.exe (process 19704) 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 . . .
\ No newline at end of file diff --git a/CST116-Ch7-Debugging/CST116-Ch7-Debugging.cpp b/CST116-Ch7-Debugging/CST116-Ch7-Debugging.cpp index f64adfe..a337a4c 100644 --- a/CST116-Ch7-Debugging/CST116-Ch7-Debugging.cpp +++ b/CST116-Ch7-Debugging/CST116-Ch7-Debugging.cpp @@ -12,7 +12,8 @@ * 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?
+* 6) Why did the value in age change? Because we entered age is = to 1 instead of ==.
+ = assigns things while == checks the number/value given from eariler.
* 7) Fix the problem and repeat Steps 2 � 5 to verify the
* problem was corrected.
* 8) Stop debugging.
@@ -26,6 +27,8 @@ * 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?
+* This is because the program is reading that anything higher than 12
+* seperately from the program reading anything that is lower than 19.
* 7) Fix the problem and repeat Steps 1 � 5 to verify the
* problem was corrected.
* 8) Stop debugging.
@@ -36,6 +39,8 @@ * 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"?
+* This is because there is a ; at the end of else with nothing before it so it is just there
+ and the program automatically reads the "adult" line because there isn't something stopping it.
* 4) Re-run the program this time with debugging and run to
* Breakpoint 2.
* 5) Why is the action with the else executing?
@@ -56,9 +61,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 (19 >= age && 12 <= age)
cout << "Teenager" << endl;
else if (age < 12)
cout << "Child" << endl;
@@ -66,7 +71,7 @@ int main() cout << "Senior" << endl;
// Breakpoint 2
// Put a breakpoint on the following line
- else;
+ else
cout << "Adult" << endl;
return 0;
|