diff options
| author | Musa Ahmed <[email protected]> | 2022-10-18 17:39:33 -0700 |
|---|---|---|
| committer | Musa Ahmed <[email protected]> | 2022-10-18 17:39:33 -0700 |
| commit | 8e5ccdfe9c245158e6c13c0dbb9710d5eb875019 (patch) | |
| tree | cbf01f3d94a5349d5fabf906906f92cf118d9e62 /CST116-Ch9-Debugging/CST116-Ch9-Debugging.cpp | |
| parent | initial commit (diff) | |
| download | cst116-ch9-debugging-m005a-8e5ccdfe9c245158e6c13c0dbb9710d5eb875019.tar.xz cst116-ch9-debugging-m005a-8e5ccdfe9c245158e6c13c0dbb9710d5eb875019.zip | |
Completed exercise 1/3
Diffstat (limited to 'CST116-Ch9-Debugging/CST116-Ch9-Debugging.cpp')
| -rw-r--r-- | CST116-Ch9-Debugging/CST116-Ch9-Debugging.cpp | 10 |
1 files 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;
|