Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to check if the number is positive.
C++
int number = 5; if (number [1] 0) { std::cout << "Positive" << std::endl; }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' will check if the number is negative.
Using '==' checks for equality, not positivity.
Using '!=' checks if number is not zero, which includes negatives.
✗ Incorrect
The '>' operator checks if the number is greater than zero, meaning positive.
2fill in blank
mediumComplete the code to print "Even" if the number is divisible by 2.
C++
int number = 4; if (number [1] 2 == 0) { std::cout << "Even" << std::endl; }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '/' divides the number but does not check remainder.
Using '*' or '+' are arithmetic operations not related to divisibility.
✗ Incorrect
The modulus operator '%' gives the remainder. If remainder is 0 when divided by 2, number is even.
3fill in blank
hardFix the error in the if statement to check if x is not equal to 10.
C++
int x = 7; if (x [1] 10) { std::cout << "Not 10" << std::endl; }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '=' causes assignment, not comparison.
Using '==' checks equality, not inequality.
Using '<' checks if less than, not inequality.
✗ Incorrect
The '!=' operator checks if x is not equal to 10. '=' is assignment, not comparison.
4fill in blank
hardFill in the blank to print "Adult" if age is 18 or more.
C++
int age = 20; if (age [1] 18) { std::cout << "Adult" << std::endl; }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<=' checks if age is less than or equal to 18, which is opposite.
Using '&&' or '||' incorrectly changes logic.
✗ Incorrect
The '>=' operator checks if age is greater than or equal to 18.
5fill in blank
hardFill all three blanks to print "Teenager" if age is between 13 and 19 inclusive.
C++
int age = 15; if (age [1] 13 [2] age [3] 19) { std::cout << "Teenager" << std::endl; }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '||' instead of '&&' allows ages outside the range.
Swapping '>=' and '<=' changes the logic.
Using '=' instead of comparison operators causes errors.
✗ Incorrect
The condition checks if age is greater or equal to 13 AND less or equal to 19 using '>=' , '&&', and '<=' operators.