You did not try with negative children and your uninitialized t happens to be 0.
Case one: small income and some kids. (Line numbers from my code version.)
* Line 1 if is true. t is set 0.
* Line 5 if is true (has kids). Line 8 is skipped, for line 5 was true.
* Line 12 if is true. cc is set (and overwrites line 6). Line 16 is skipped, for line 12 was true.
Case two: large income and some kids.
* Line 1 is false.
* Line 5 if is true (has kids). Line 8 is skipped, for line 5 was true.
* Line 12 if is true. cc is set (and overwrites line 6). Line 16 is skipped, for line 12 was true.
* t remains whatever uninitialized value it had.
Braces, properly:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
|
int c = 0; // accept only whole kids
std::cout >> c;
if ( c < 0 ) c = 0; // sanity check
if ( i <= 30000 ) {
// set t and cc
}
else if ( i <= 100000 ) {
// i cannot be less than 30k, because previous if was false
// set t and cc
}
else {
// set t and cc
}
// show values
| |