Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to read an integer from the user using cin.
C++
#include <iostream> using namespace std; int main() { int number; cin [1] number; cout << "You entered: " << number << endl; return 0; }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using << instead of >> with cin.
Using assignment operator = instead of >>.
✗ Incorrect
The operator >> is used with cin to take input from the user.
2fill in blank
mediumComplete the code to read a double value from the user using cin.
C++
#include <iostream> using namespace std; int main() { double value; cin [1] value; cout << "Value: " << value << endl; return 0; }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using << instead of >> with cin.
Using assignment operator = instead of >>.
✗ Incorrect
Use >> with cin to read input into variables.
3fill in blank
hardFix the error in the code to correctly read a string using cin.
C++
#include <iostream> #include <string> using namespace std; int main() { string name; cin [1] name; cout << "Hello, " << name << "!" << endl; return 0; }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using << instead of >> with cin.
Using = instead of >>.
✗ Incorrect
Use >> with cin to read a string without spaces.
4fill in blank
hardFill both blanks to read two integers from the user and print their sum.
C++
#include <iostream> using namespace std; int main() { int a, b; cin [1] a [2] b; cout << "Sum: " << a + b << endl; return 0; }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using << instead of >> for input.
Using only one operator for two variables.
✗ Incorrect
Use >> twice to read two integers from the user.
5fill in blank
hardFill all three blanks to read a character, an integer, and a double, then print them.
C++
#include <iostream> using namespace std; int main() { char ch; int num; double val; cin [1] ch [2] num [3] val; cout << "Char: " << ch << ", Int: " << num << ", Double: " << val << endl; return 0; }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using << instead of >> for input.
Missing one or more input operators.
✗ Incorrect
Use >> three times to read the three values from the user.