Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to check if a number is positive.
C++
#include <iostream> int main() { int num = 5; if (num [1] 0) { std::cout << "Positive" << std::endl; } return 0; }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' instead of '>' will check for negative numbers.
Using '==' checks for equality, not positivity.
✗ Incorrect
The condition 'num > 0' checks if the number is positive.
2fill in blank
mediumComplete the code to check if a number is between 1 and 10 (inclusive).
C++
#include <iostream> int main() { int num = 7; if (num [1] 1 && num [2] 10) { std::cout << "In range" << std::endl; } return 0; }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '>' or '<' excludes the boundary numbers.
Using '||' instead of '&&' allows numbers outside the range.
✗ Incorrect
The condition 'num >= 1 && num <= 10' checks if num is between 1 and 10 inclusive.
3fill in blank
hardFix the error in the nested if statement to check if a number is positive and even.
C++
#include <iostream> int main() { int num = 4; if (num > 0) { if (num [1] 2 == 0) { std::cout << "Positive and even" << std::endl; } } return 0; }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '/' divides the number but does not check evenness.
Using '*' or '+' are arithmetic operations unrelated to checking evenness.
✗ Incorrect
The modulus operator '%' checks if the remainder is zero, meaning the number is even.
4fill in blank
hardFill both blanks to complete the nested conditional that prints if a number is positive and divisible by 3.
C++
#include <iostream> int main() { int num = 9; if (num [1] 0) { if (num [2] 3 == 0) { std::cout << "Positive and divisible by 3" << std::endl; } } return 0; }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' instead of '>' for positivity.
Using '/' instead of '%' for divisibility check.
✗ Incorrect
The first condition checks if num is greater than 0, the second uses '%' to check divisibility by 3.
5fill in blank
hardFill all three blanks to create a nested conditional that prints if a number is negative, odd, and less than -10.
C++
#include <iostream> int main() { int num = -15; if (num [1] 0) { if (num [2] 2 != 0) { if (num [3] -10) { std::cout << "Negative, odd, and less than -10" << std::endl; } } } return 0; }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '>' instead of '<' for negativity or less than -10.
Using '/' instead of '%' for oddness check.
✗ Incorrect
The first condition checks if num is less than 0 (negative), the second uses '%' to check oddness, the third checks if num is less than -10.