diff options
Diffstat (limited to 'CST116-Ch9-Debugging/CST116-Ch9-Debugging-Chambers.cpp')
| -rw-r--r-- | CST116-Ch9-Debugging/CST116-Ch9-Debugging-Chambers.cpp | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/CST116-Ch9-Debugging/CST116-Ch9-Debugging-Chambers.cpp b/CST116-Ch9-Debugging/CST116-Ch9-Debugging-Chambers.cpp index fea10fb..425444a 100644 --- a/CST116-Ch9-Debugging/CST116-Ch9-Debugging-Chambers.cpp +++ b/CST116-Ch9-Debugging/CST116-Ch9-Debugging-Chambers.cpp @@ -12,15 +12,18 @@ * 4) Add another watch using &age for the name. This will display * the address of age. * 5) Write down the address of age. +* 0x0000006e926ffb24 {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? +* It changes the address and value of age because we have not yet made it a global int for the rest of our program to use. * 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 did transfer back, but then is immediately reset 0 inside the main function. * 15) Stop debugging and fix the error. * 16) Run to Breakpoint 1. * 17) Step over the function call to GetAge. @@ -36,6 +39,7 @@ * 4) Step into one more time so that the current line is the * calculation. * 5) Why is age greyed out in your watch window? +* Because age is not needed for this calculation. * 6) Stop debugging. * * Debugging Exercise 3 @@ -68,12 +72,12 @@ const int DAYS_PER_YEAR = 365; int GetAge(); int CalcDays(int age); +int age; +int days; void PrintResults(int age, int days); int main() { - int age = 0; - int days = 0; // Breakpoint 1 // Put breakpoint on the following line @@ -84,11 +88,10 @@ int main() // Put breakpoint on the following line PrintResults(age, days); - return 0; + return age; } int GetAge() { - int age; cout << "Please enter your age: "; cin >> age; @@ -107,4 +110,4 @@ void PrintResults(int days, int age) { cout << age << "! Boy are you old!\n"; cout << "Did you know that you are at least " << days << " days old?\n\n"; -} +}
\ No newline at end of file |