= 18 cout <"You can vote in U.S elections < endl"/>
cs31day7 Wk 3 W

# cs31day7 Wk 3 W - If(citizenship ="US age >= 18 cout <"You...

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

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;

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

View Full Document
} } __________________________ Simplified Verison
This is the end of the preview. Sign up to access the rest of the document.

## This note was uploaded on 02/02/2011 for the course CS 31 taught by Professor Melkanoff during the Spring '00 term at UCLA.

### Page1 / 7

cs31day7 Wk 3 W - If(citizenship ="US age >= 18 cout <"You...

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

View Full Document
Ask a homework question - tutors are online