diff options
| author | Morgan Cyrus <[email protected]> | 2022-10-12 20:36:59 -0700 |
|---|---|---|
| committer | Morgan Cyrus <[email protected]> | 2022-10-12 20:36:59 -0700 |
| commit | 3138e6bce864466472fff7dd6295b2705492fcf1 (patch) | |
| tree | 6a87850356ded573d05158548eb4003e54b5cbce | |
| parent | beginning exercise 3 (diff) | |
| download | cst116-ch7-cyrus-3138e6bce864466472fff7dd6295b2705492fcf1.tar.xz cst116-ch7-cyrus-3138e6bce864466472fff7dd6295b2705492fcf1.zip | |
Added {} brackets to all of the statements.
| -rw-r--r-- | CST116-Ch7-Debugging/CST116-Ch7-Debugging.cpp | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/CST116-Ch7-Debugging/CST116-Ch7-Debugging.cpp b/CST116-Ch7-Debugging/CST116-Ch7-Debugging.cpp index 6663f38..fd649e1 100644 --- a/CST116-Ch7-Debugging/CST116-Ch7-Debugging.cpp +++ b/CST116-Ch7-Debugging/CST116-Ch7-Debugging.cpp @@ -68,9 +68,14 @@ * Debugging Exercise 3
*
* 1) Run the program without debugging.
+* done
*
* 2) When prompted, enter the value of 10 for your age.
+* done
+*
* 3) Why does the program print both "Child" and "Adult"?
+* the brackets {} were left out for the if, else if, and else statements.
+*
* 4) Re-run the program this time with debugging and run to
* Breakpoint 2.
* 5) Why is the action with the else executing?
@@ -92,17 +97,27 @@ int main() // 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;
+ else
+ {
+ cout << "Adult" << endl;
+ }
return 0;
}
\ No newline at end of file |