Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to check if the number is positive.
C++
#include <iostream> using namespace std; int main() { int num = 10; if (num [1] 0) { cout << "Positive number" << endl; } return 0; }
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 else-if ladder to check if a number is negative.
C++
#include <iostream> using namespace std; int main() { int num = -5; if (num > 0) { cout << "Positive" << endl; } else if (num [1] 0) { cout << "Negative" << endl; } else { cout << "Zero" << endl; } return 0; }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '==' which only checks for zero.
Using '>=' which includes zero and positive numbers.
✗ Incorrect
The condition num < 0 checks if the number is negative.
3fill in blank
hardFix the error in the else-if ladder condition to correctly check for zero.
C++
#include <iostream> using namespace std; int main() { int num = 0; if (num > 0) { cout << "Positive" << endl; } else if (num [1] 0) { cout << "Zero" << endl; } else { cout << "Negative" << endl; } return 0; }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' or '>' which check for negative or positive numbers.
Using '!=' which checks for not equal, not zero.
✗ Incorrect
The condition num == 0 correctly checks if the number is zero.
4fill in blank
hardFill both blanks to complete the else-if ladder that prints the number's sign.
C++
#include <iostream> using namespace std; int main() { int num = -3; if (num [1] 0) { cout << "Positive" << endl; } else if (num [2] 0) { cout << "Negative" << endl; } else { cout << "Zero" << endl; } return 0; }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping the operators in the conditions.
Using '==' or '!=' in the first two conditions.
✗ Incorrect
The first condition checks if num > 0 (positive), the second checks if num < 0 (negative).
5fill in blank
hardFill all three blanks to create an else-if ladder that prints "Positive", "Negative", or "Zero" based on the number.
C++
#include <iostream> using namespace std; int main() { int num = 0; if (num [1] 0) { cout << "Positive" << endl; } else if (num [2] 0) { cout << "Negative" << endl; } else if (num [3] 0) { cout << "Zero" << endl; } return 0; }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '!=' instead of '==' for zero check.
Mixing up the order of conditions.
✗ Incorrect
The conditions check if num > 0 (positive), num < 0 (negative), and num == 0 (zero).