From 8e5ccdfe9c245158e6c13c0dbb9710d5eb875019 Mon Sep 17 00:00:00 2001 From: Musa Ahmed Date: Tue, 18 Oct 2022 17:39:33 -0700 Subject: Completed exercise 1/3 --- CST116-Ch9-Debugging/CST116-Ch9-Debugging.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/CST116-Ch9-Debugging/CST116-Ch9-Debugging.cpp b/CST116-Ch9-Debugging/CST116-Ch9-Debugging.cpp index eff8980..204eaf2 100644 --- a/CST116-Ch9-Debugging/CST116-Ch9-Debugging.cpp +++ b/CST116-Ch9-Debugging/CST116-Ch9-Debugging.cpp @@ -16,11 +16,15 @@ * 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 address changed becasue we re-instantiated the variable age in the function, +* but we didn't specify a number for it so it's just filled wiht garbage * 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? +* This is because we are setting the age back to zero at the start of the main function, +* thus it is resetting the age every time. * 15) Stop debugging and fix the error. * 16) Run to Breakpoint 1. * 17) Step over the function call to GetAge. @@ -64,6 +68,8 @@ using std::cout; using std::cin; using std::endl; +int age = 0; + const int DAYS_PER_YEAR = 365; int GetAge(); @@ -72,7 +78,7 @@ void PrintResults(int age, int days); int main() { - int age = 0; + int days = 0; // Breakpoint 1 @@ -88,7 +94,7 @@ int main() } int GetAge() { - int age; + cout << "Please enter your age: "; cin >> age; -- cgit v1.2.3