aboutsummaryrefslogtreecommitdiff
path: root/CST116-Ch7-Debugging/CST116-Ch7-Debugging.cpp
blob: c67ba7b27d90ad1c327a3f6a38d02abd03be04c8 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
/********************************************************************
* File: CST116-Ch7-Debugging.cpp
* 
* Trevor Bouchillon
* CST-116
*
* General Instructions: Complete each step before proceeding to the
* next.
*
* Debugging Exercise 1
*
* 1) Insert a breakpoint on the lines indicated in the code.
* 2) Run to Breakpoint 1.
* 3) When prompted, enter your age.
* 4) When the execution stops, add a watch on age and verify that
*    the value in age is what you typed in.
* 5) Step over the if statement.
* 6) Why did the value in age change?
* ***************************************************************************
* The value in age changed because because within the if statement age is supposed 
  to be compared to the age of 1, but the code is actually not comparing but is instead 
  assigning it the value of 1. 
* ***************************************************************************
* 7) Fix the problem and repeat Steps 2 � 5 to verify the
*    problem was corrected.
* 8) Stop debugging.
*
* Debugging Exercise 2
*
* 1) Run to Breakpoint 1.
* 2) When prompted, enter the value 25 for your age.
* 3) Step over the if statement. Execution of the program should
*    continue on the else if statement.
* 4) Verify that 25 is still stored in age.
* 5) Step over the else if.
* 6) Why is the program going to print "Teenager" for an age of 25?
* ************************************************************************************************************************
* Because the compare operator is not correct. It needs to be && not ||, which is a "or" operator.
* ************************************************************************************************************************
* 7) Fix the problem and repeat Steps 1 � 5 to verify the
*    problem was corrected.
* 8) Stop debugging.
* 9) Remove Breakpoint1.
*
* Debugging Exercise 3
*
* 1) Run the program without debugging.
* 2) When prompted, enter the value of 10 for your age.
* 3) Why does the program print both "Child" and "Adult"?
* ************************************************************************************************************************
* Because the else statement has a semicolon at the end of it, so its not actually executing amything that else statement includes, because it doesn't include anything
* Deleting that semicolon makes the print out of adult part of the else statement. Otherwise its just always going to print adult. 
* ************************************************************************************************************************
* 4) Re-run the program this time with debugging and run to
*    Breakpoint 2.
* 5) Why is the action with the else executing?
* ************************************************************************************************************************
* Becuase the age entered does not fall within any of the if statement. 
* ************************************************************************************************************************
* 6) Fix the problem and re-run to verify the problem was corrected.
********************************************************************/

#include <iostream>
using std::cout;
using std::endl;
using std::cin;

int main()
{
    int age = 0;

    cout << "Enter your age: ";
    cin >> age;

    // Breakpoint 1
    // Put a breakpoint on the following line
    if (age == 1)
        cout << "First Birthday" << endl;
    else if (age >= 12 && age <= 19)
        cout << "Teenager" << endl;
    else if (age < 12)
        cout << "Child" << endl;
    else if (age > 62)
        cout << "Senior" << endl;
    // Breakpoint 2
    // Put a breakpoint on the following line
    else cout << "Adult" << endl;

    return 0;
}