cs31day7 Wk 3 W

cs31day7 Wk 3 W - If (citizenship = "US" &...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
cout << "You can vote in U.S. elections" << endl; If (citizenship != "US" || age < 18) cout << "You cannot vote in U.S. elections" << endl; De Morgan's Laws: not (A and B) --> (not A) or (not B) not (A or B) --> (not A) and (not B) not (a > b) --> a <= b not (a >= b) --> a < b not (a < b) --> a >= b not (a <= b) --> a > b if (citizenship != "US" || citizenship != "Canada") // problem: this is always true ... if (citizenship != "US" && citizenship != "Canada") // what was meant ... if (age == 17 || age == 18) ... There is some unnecessary information in the following code: if (income < 30000) cout << "Low" << endl; else { // You can't get to the else part if income < 30000 if (income >= 30000 && income < 100000) // That means test for income >= 30000 is redundant cout << "Middle" << endl; else { if (income >= 100000 && income < 500000) // The only way to get here is if income >= 100000 cout << "High" << endl; // This means that check for income >= 100000 is redundant else // This part is also a single statement so {} not needed cout << "Very High" << endl;
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
} } __________________________ Simplified Verison
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 7

cs31day7 Wk 3 W - If (citizenship = &quot;US&quot; &amp;...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online