From 233137487edd936bcb08e5ce93ba8e864c5a4fb7 Mon Sep 17 00:00:00 2001 From: EdwardFine Date: Thu, 6 Oct 2022 15:55:11 -0700 Subject: Fixed code --- CST116-Ch9-Debugging/CST116-Ch9-Debugging.cpp | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) (limited to 'CST116-Ch9-Debugging/CST116-Ch9-Debugging.cpp') diff --git a/CST116-Ch9-Debugging/CST116-Ch9-Debugging.cpp b/CST116-Ch9-Debugging/CST116-Ch9-Debugging.cpp index eff8980..52a15fa 100644 --- a/CST116-Ch9-Debugging/CST116-Ch9-Debugging.cpp +++ b/CST116-Ch9-Debugging/CST116-Ch9-Debugging.cpp @@ -16,11 +16,18 @@ * 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? +* Inside the function of GetAge, the int age is reestablished after already +* being established at the start of the code to equal 0.However this time +* age was defined to a specific number, so a default placeholder number was +* asigned to age, which changes the stored value shown in the address. * 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? +* The value entered wasn't reasigned to the age in main, it was just established +* in the age in GetAge, by adding age = before the GetAge function, it assigns +* the age in main to the age returned from the GetAge function. * 15) Stop debugging and fix the error. * 16) Run to Breakpoint 1. * 17) Step over the function call to GetAge. @@ -36,6 +43,9 @@ * 4) Step into one more time so that the current line is the * calculation. * 5) Why is age greyed out in your watch window? +* Age is greyed out in my watch window because the function, even though it +* calls for age, is expecting a years int. So by changing years to age, +* it removes the grey and calculates properly. * 6) Stop debugging. * * Debugging Exercise 3 @@ -47,6 +57,11 @@ * 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 values changed because then the function is called in main, it gives +* age and days in that order, but when the function recieves them, it +* expects them to be in order of days and then age. To fix this you can +* either swap the sent values or the expected values. For my fix, I +* will swap the expected variables. * 7) Stop debugging and fix the error. * * Debugging Exercise 4 @@ -77,7 +92,7 @@ int main() // Breakpoint 1 // Put breakpoint on the following line - GetAge(); + age = GetAge(); days = CalcDays(age); // Breakpoint 2 @@ -95,15 +110,15 @@ int GetAge() return age; } -int CalcDays(int years) +int CalcDays(int age) { int days; - days = years * DAYS_PER_YEAR; + days = age * DAYS_PER_YEAR; 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"; -- cgit v1.2.3