Challenge - 5 Problems
InputOutputMaster
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
What is the output of this C++ code?
Consider the following code snippet. What will be printed when the input is
5 10?C++
#include <iostream> using namespace std; int main() { int a, b; cin >> a >> b; cout << a + b << endl; return 0; }
Attempts:
2 left
💡 Hint
Remember that operator >> reads integers and skips spaces.
✗ Incorrect
The code reads two integers 5 and 10, then outputs their sum, which is 15.
❓ Predict Output
intermediate2:00remaining
What does this code print given input "Hello World"?
Look at this code. What will it output if the user types
Hello World?C++
#include <iostream> #include <string> using namespace std; int main() { string s; cin >> s; cout << s << endl; return 0; }
Attempts:
2 left
💡 Hint
cin >> string reads only until the first space.
✗ Incorrect
cin >> s reads only the first word 'Hello' and stops at the space.
❓ Predict Output
advanced2:00remaining
What is the output of this code reading multiple inputs?
Given the input
3 4 5, what will this program print?C++
#include <iostream> using namespace std; int main() { int x, y, z; cin >> x >> y >> z; cout << x << y << z << endl; return 0; }
Attempts:
2 left
💡 Hint
cout with multiple << outputs values without spaces.
✗ Incorrect
The program prints the three integers concatenated without spaces: 345.
❓ Predict Output
advanced2:00remaining
What error does this code cause?
What error will this code produce when run?
C++
#include <iostream> using namespace std; int main() { int a; cout << "Enter a number: "; cin >> a; cout << "You entered: " << b << endl; return 0; }
Attempts:
2 left
💡 Hint
Check variable names carefully.
✗ Incorrect
Variable 'b' is used but never declared, causing a compilation error.
🧠 Conceptual
expert2:30remaining
What is the output of this code with mixed input types?
Given the input
42 hello 3.14, what will this program output?C++
#include <iostream> #include <string> using namespace std; int main() { int i; string s; double d; cin >> i >> s >> d; cout << s << " " << i << " " << d << endl; return 0; }
Attempts:
2 left
💡 Hint
cin reads inputs in order and cout prints in the order given.
✗ Incorrect
cin reads 42 into i, 'hello' into s, and 3.14 into d. cout prints s, i, d in that order.