Conditional Statements and Randomness
February 22nd, 2016
Lecture Code
Conditional Statements
- slides
- Cannot do a switch on a variable of type double
- Any switch can be converted to an if-elseif, but an if-elseif
may not be able to be converted to a switch
Blackjack (In-Class Project)
- Finish initial phase of development and address some problems.
- Modify Friday's BlackJack program so that it (1) generates the cards randomly and (2) prints the two cards in the hand, as well as the score.
Conditional Statements
- Conditional statements let us execute different code based on
whether or not something is true.
- Standard conditional statements are: if, if-else,
if-elseif-elseif..., switch.
- if-elseif versus switch statement.
- Single "=" is assignment, double "==" is a test.
- Less than: <. Greater than: >. Less than or equal to:
<=. Greater than or equal to: >=.
- "&&" is and, "||" is or (on my keyboard, "|" is on the
same key as the "\").
- See sample code above for examples.
Randomness
slides