diff options
Diffstat (limited to 'CST116-Ch9-Debugging/CST116-Ch9-Debugging.cpp')
| -rw-r--r-- | CST116-Ch9-Debugging/CST116-Ch9-Debugging.cpp | 21 |
1 files changed, 18 insertions, 3 deletions
diff --git a/CST116-Ch9-Debugging/CST116-Ch9-Debugging.cpp b/CST116-Ch9-Debugging/CST116-Ch9-Debugging.cpp index eff8980..322da77 100644 --- a/CST116-Ch9-Debugging/CST116-Ch9-Debugging.cpp +++ b/CST116-Ch9-Debugging/CST116-Ch9-Debugging.cpp @@ -12,15 +12,24 @@ * 4) Add another watch using &age for the name. This will display
* the address of age.
* 5) Write down the address of age.
+*
+* 0x0000001d27d8f854{0}
+*
* 6) Step Into the code for the function GetAge.
* 7) The execution continues to the function header for GetAge.
* 8) Step into one more time.
* 9) Why did the address of age and value change?
+*
+* -The program has entered a new block which make the age defined in the new block different from the original "age" changing the address of the variable-
+*
* 10) Step over the cout and cin statements.
* 11) Verify the value entered is stored properly in age.
* 12) Step into until the flow returns to main.
* 13) Step over one more time.
* 14) Why didn't the value entered get transferred back to main?
+*
+* -It didn't trasfer because when the program left the block that the variable was defined only within it and left the definition as well-
+*
* 15) Stop debugging and fix the error.
* 16) Run to Breakpoint 1.
* 17) Step over the function call to GetAge.
@@ -47,6 +56,9 @@ * 4) Step into the PrintResults function.
* 5) Age is 7300? Not even Ralph is that old.
* 6) Why did the values for both variables change?
+*
+* -The print results inverted the values mixing them up-
+*
* 7) Stop debugging and fix the error.
*
* Debugging Exercise 4
@@ -70,19 +82,22 @@ int GetAge(); int CalcDays(int age);
void PrintResults(int age, int days);
+
int main()
{
int age = 0;
int days = 0;
+
// Breakpoint 1
// Put breakpoint on the following line
- GetAge();
+ age = GetAge();
+
days = CalcDays(age);
// Breakpoint 2
// Put breakpoint on the following line
- PrintResults(age, days);
+ PrintResults(age,days);
return 0;
}
@@ -103,7 +118,7 @@ int CalcDays(int years) return days;
}
-void PrintResults(int days, int age)
+void PrintResults(int age, int days)
{
cout << age << "! Boy are you old!\n";
cout << "Did you know that you are at least " << days << " days old?\n\n";
|