0
0
C++programming~10 mins

Relational operators in C++ - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to check if a is less than b.

C++
bool result = a [1] b;
Drag options to blanks, or click blank then click option'
A!=
B>
C<
D==
Attempts:
3 left
💡 Hint
Common Mistakes
Using '>' instead of '<' reverses the comparison.
Using '==' checks equality, not less than.
2fill in blank
medium

Complete the code to check if x is greater than or equal to y.

C++
if (x [1] y) {
    // do something
}
Drag options to blanks, or click blank then click option'
A<
B<=
C==
D>=
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<=' checks the opposite condition.
Using '==' only checks equality.
3fill in blank
hard

Fix the error in the code to correctly check if num is not equal to 10.

C++
if (num [1] 10) {
    // do something
}
Drag options to blanks, or click blank then click option'
A!=
B==
C=
D<>
Attempts:
3 left
💡 Hint
Common Mistakes
Using '=' assigns a value instead of comparing.
Using '<>' is not valid in C++.
4fill in blank
hard

Fill both blanks to create a condition that checks if val is between 5 and 15 inclusive.

C++
if (val [1] 5 && val [2] 15) {
    // do something
}
Drag options to blanks, or click blank then click option'
A>=
B<
C<=
D>
Attempts:
3 left
💡 Hint
Common Mistakes
Using '>' or '<' excludes the boundary values.
Mixing up the operators reverses the logic.
5fill in blank
hard

Fill all three blanks to create a condition that checks if score is greater than 50, less than 100, and not equal to 75.

C++
if (score [1] 50 && score [2] 100 && score [3] 75) {
    // do something
}
Drag options to blanks, or click blank then click option'
A<
B>
C!=
D<=
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<=' or '>=' changes the range boundaries.
Using '==' instead of '!=' includes 75.