chapter 2
The following code will have what result? int test = 10; while (test == 10) { cout << test; }
An infinite loop
To check if a value is not equal to another value, use which relational operator?
!=
The value of 'score' will be between what range of numbers? int score = (rand() % 50) + 1;
1 and 50
The expression (5-5) evaluates to true
False
Seeding a random number generator does what?
Make sure the starting point for our number sequence is in a different spot each time
Using a switch statement allows us to do what?
Provide different code to run for different possible values of a variable
Code provided for each case in a switch statement can and should be separated by what keyword?
break
What keyword can we use to provide code that will execute if the expression in an 'if' statement evaluates to false?
else
Find the error in the following code. if (5 < 10); { std::cout << 'This is displayed'; }
There shouldn't be a semicolon after (5 < 10)
Initializing a variable used in the loop expression is necessary for a 'while' loop, but not required for a 'do' loop.
True
Switch statements can only be used with values that can be evaluated as an 'int'.
True
What will the following expression evaluate to (in boolean format)? ((5 < 5 || 5 > 3) && 5 >= 5)
True
The 'default' expression provided in a switch statement will run no matter what the value of the switch target is.
False
The rand() function will generate random numbers is a different sequence each time, whether we seed it or not.
False
To check if two values are equal, use the '=' relational operator.
False
What will the following expression evaluate to (in boolean format)? (5 < 10 && 5 < 5)
False
What will the following expression evaluate to (in boolean format)? (5 < 2 || (5 == 5 && 5 <= 3))
False
You have to place a semicolon after the closing curcly brace of an if statement.
False
In the following code, what message(s) will be displayed to the output? if (5 != 5) { std::cout << 'Message 1'; if (5 > 5) { std::cout << 'Message 2'; } } else { std::cout << 'Message 3'; }
Message 3
What will the following expression evaluate to (in boolean format)? (5 >= 10 || 5 == 5)
True
Printing our player's score to the screen is an example of what step in the 'Game loop'?
Updating the display
To stop a loop and continue at the code below the loop statements, use what keyword?
break
What is the difference between a 'while' loop and a 'do' loop?
'While' loops evaluate their expression before their statement block, 'do' loops evaluate after
In the following expression, what will the value of 'score' be at the end? int score = 10; if (5 <= 4) { score++; }
10