Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to include the standard input-output library.
C++
#include [1]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using which is a C library, not standard for C++ input/output.
Forgetting the angle brackets around the library name.
✗ Incorrect
The <iostream> header is required for input and output operations in C++.
2fill in blank
mediumComplete the code to start the main function.
C++
int [1]() { return 0; }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using other function names like start or begin which are not recognized as entry points.
Omitting the parentheses after the function name.
✗ Incorrect
The main function is the entry point of every C++ program.
3fill in blank
hardFix the error in the code to print "Hello, World!".
C++
#include <iostream> int main() { std::cout [1] "Hello, World!" << std::endl; return 0; }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using the extraction operator >> which is for input.
Using assignment or addition operators which are incorrect here.
✗ Incorrect
The insertion operator << is used with std::cout to print output.
4fill in blank
hardFill both blanks to declare and initialize an integer variable named count with value 10.
C++
[1] [2] = 10;
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using float instead of int for an integer variable.
Using invalid variable names or reserved words.
✗ Incorrect
int declares an integer type, and count is the variable name.
5fill in blank
hardFill all three blanks to create a simple for loop that prints numbers 1 to 5.
C++
for (int [1] = 1; [2] <= 5; [3]++) { std::cout << i << std::endl; }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using different variable names in different parts of the loop.
Using a variable name not declared in the loop.
✗ Incorrect
The variable i is used as the loop counter in all parts of the for loop.