Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to check if a number is positive.
C++
int num = 5; if (num [1] 0) { std::cout << "Positive" << std::endl; }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '==' instead of '>' to check positivity.
Using '<' which checks for negative numbers.
✗ Incorrect
The condition num > 0 checks if the number is positive.
2fill in blank
mediumComplete the code to print "Even" if the number is even.
C++
int num = 4; if (num % 2 [1] 0) { std::cout << "Even" << std::endl; }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '!=' which checks for odd numbers.
Using '>' or '<' which are not suitable here.
✗ Incorrect
The condition num % 2 == 0 checks if the number is even.
3fill in blank
hardFix the error in the if–else statement to print "Positive" or "Non-positive".
C++
int num = -3; if (num [1] 0) { std::cout << "Positive" << std::endl; } else { std::cout << "Non-positive" << std::endl; }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<=' which reverses the logic.
Using '==' which only checks for zero.
✗ Incorrect
The condition num > 0 correctly checks for positive numbers.
4fill in blank
hardFill both blanks to print "Adult" if age is 18 or more, otherwise "Minor".
C++
int age = 20; if (age [1] 18) { std::cout << "Adult" << std::endl; } else { std::cout << "[2]" << std::endl; }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' instead of '>=' for the condition.
Printing "Adult" in the else block.
✗ Incorrect
The condition age >= 18 checks if the person is an adult. Otherwise, print "Minor".
5fill in blank
hardFill all three blanks to print "Positive", "Negative", or "Zero" based on the value of num.
C++
int num = 0; if (num [1] 0) { std::cout << "Positive" << std::endl; } else if (num [2] 0) { std::cout << "Negative" << std::endl; } else { std::cout << "[3]" << std::endl; }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '!=' which does not distinguish zero.
Mixing up the comparison operators.
✗ Incorrect
The first condition checks if num > 0 (positive), the second if num < 0 (negative), else print "Zero".