Challenge - 5 Problems
Conditional Logic Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of conditional logic in C++
What is the output of this C++ code snippet?
C++
#include <iostream> int main() { int x = 10; if (x > 5) { std::cout << "Greater" << std::endl; } else { std::cout << "Smaller or equal" << std::endl; } return 0; }
Attempts:
2 left
💡 Hint
Check the condition if (x > 5).
✗ Incorrect
Since x is 10, which is greater than 5, the if block runs and prints "Greater".
🧠 Conceptual
intermediate1:30remaining
Why use conditional logic?
Why do programmers use conditional logic in their code?
Attempts:
2 left
💡 Hint
Think about how programs choose what to do next.
✗ Incorrect
Conditional logic lets programs decide what to do depending on different situations or values.
❓ Predict Output
advanced2:00remaining
Output with nested if-else
What will this C++ program print?
C++
#include <iostream> int main() { int score = 75; if (score >= 90) { std::cout << "A" << std::endl; } else if (score >= 70) { std::cout << "B" << std::endl; } else { std::cout << "C" << std::endl; } return 0; }
Attempts:
2 left
💡 Hint
Check which condition score = 75 satisfies.
✗ Incorrect
75 is not >= 90, so first if is false. It is >= 70, so second condition is true, printing "B".
🔧 Debug
advanced2:30remaining
Find the error in conditional logic
This code is supposed to print "Positive" if number is greater than zero, but it does not compile. What is the error?
C++
#include <iostream> int main() { int number = 5; if number > 0 { std::cout << "Positive" << std::endl; } return 0; }
Attempts:
2 left
💡 Hint
Check the syntax of the if statement.
✗ Incorrect
In C++, the condition in an if statement must be inside parentheses: if (condition).
🚀 Application
expert3:00remaining
Predict the output of complex conditional logic
What is the output of this C++ program?
C++
#include <iostream> int main() { int a = 3, b = 4, c = 5; if (a > b) { if (b > c) { std::cout << "X" << std::endl; } else { std::cout << "Y" << std::endl; } } else if (a + b > c) { std::cout << "Z" << std::endl; } else { std::cout << "W" << std::endl; } return 0; }
Attempts:
2 left
💡 Hint
Check each condition step by step with a=3, b=4, c=5.
✗ Incorrect
a > b is false (3 > 4 false), so first if block skipped. Next, a + b > c is 7 > 5 true, so prints "Z".