0
0
C++programming~10 mins

Why conditional logic is needed in C++ - Test Your Understanding

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

Complete the code 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'
A>=
B<
C==
D!=
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' will check if age is less than 18, which is wrong here.
Using '==' checks only if age is exactly 18, not more.
2fill in blank
medium

Complete the code to print "Even" if the number is divisible by 2.

C++
int number = 10;
if (number [1] 2 == 0) {
    std::cout << "Even" << std::endl;
}
Drag options to blanks, or click blank then click option'
A%
B/
C*
D+
Attempts:
3 left
💡 Hint
Common Mistakes
Using '/' divides the number but does not check for evenness.
Using '*' or '+' does not relate to divisibility.
3fill in blank
hard

Fix the error in the condition to check if score is less than 50.

C++
int score = 45;
if (score [1] 50) {
    std::cout << "Fail" << std::endl;
}
Drag options to blanks, or click blank then click option'
A>
B==
C>=
D<
Attempts:
3 left
💡 Hint
Common Mistakes
Using '>' checks if score is greater than 50, which is wrong here.
Using '>=' or '==' do not check for less than.
4fill in blank
hard

Fill both blanks to print "Teenager" if age is between 13 and 19 inclusive.

C++
int age = 15;
if (age [1] 13 && age [2] 19) {
    std::cout << "Teenager" << std::endl;
}
Drag options to blanks, or click blank then click option'
A>=
B<
C<=
D>
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' or '>' alone excludes boundary ages.
Using wrong operators reverses the logic.
5fill in blank
hard

Fill in the blanks to print "Grade A" if score is above 90, "Grade B" if score is above 80, else "Grade C".

C++
int score = 85;
if (score [1] 90) {
    std::cout << "Grade A" << std::endl;
} else if (score [2] 80) {
    std::cout << "Grade B" << std::endl;
} else {
    std::cout << "Grade C" << std::endl;
}
Drag options to blanks, or click blank then click option'
A>
B>=
C<=
D<
Attempts:
3 left
💡 Hint
Common Mistakes
Using '>=' includes the boundary which may change grading logic.
Using '<=' or '<' in conditions here is incorrect.