Announcements and Reminders
|
Topics |
Terminology |
||
rand() function and mod practiceExample - write code
to simulate rolling two dice.
How to seed the random number generator Chapter 4if statementsif ( condition ) statement;if ( condition ) statement; if ( condition ) { block of statements } if ( condition ) { block of statements } expressionsrelational operators> < == >= <= !=bool type The boolalpha manipulator logical operators&&and is an alias for
&&
||or is an alias for ||
!not is an alias for !
Common if statement problemsif ( x > y );cout << " x > y "; if (x = y) cout << " x = y "; if (x <= y) cout << " x is less "; cout << " than y "; if ... elseProgram 4-8 - Page 168Program 4-9 - Page 169 Nested ifProgram 4-10 - Page 172Program 4-11 - Page 173 The dangling else if (condition) ... if (condition) ... else ... sequence of if statementsif ( condition )statement or block if ( condition ) statement or block if ( condition ) statement or block if ( condition ) statement or block ... sequence of if ... else statmentsif ( condition )statement or block else if ( condition ) statement or block else if ( condition ) statement or block else if ( condition ) statement or block else statement or block if ... else Review Problems
Program 4-20 - Page 197-198 The string == operatorThe conditional operatoraka ternary operatorcondition expression1 ? expression2 : expression3 If the condition express1 is true, the operator returns expression2 otherwise it returns expression3. The switch statementSyntax:switch (integral expression) { case (integral value1): statement(s) case (integral value2): statement(s) case (integral value3): statement(s) default: } block and scope Example: Assign a letter grade for 90 - 100% = A 80 - 89% = B 70 - 79% = C 60 - 69% = D less than 60% = F Example: Write a program to simulate a random playing card and printing the value of a random card, such as queen of clubs Videos if statement if Statement.....again? if / else Statement Read me |
if
statement condition block scope expression logical value type bool true false relational operator >
logical operator< == >= <= != &&
alias|| ! and
or not fall through else nested if three way condition dangling else |