Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to print "Hello, World!" in C++.
C++
#include <iostream> int main() { std::cout << [1] << std::endl; return 0; }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting the double quotes around the text.
Using std::endl as the text to print.
✗ Incorrect
The text to print must be a string literal enclosed in double quotes.
2fill in blank
mediumComplete the code to declare an integer variable named 'count' and initialize it to 10.
C++
int [1] = 10;
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a different variable name than 'count'.
Missing the semicolon at the end.
✗ Incorrect
The variable name must be 'count' as requested.
3fill in blank
hardFix the error in the code to correctly compile and run.
C++
#include <iostream> int main() { int sum = 10; std::cout << "Sum is: " << [1] << std::endl; return 0; }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Adding a semicolon inside the std::cout expression.
Using sum() as if it were a function.
✗ Incorrect
The variable 'sum' should be used without a semicolon inside the output statement, and the statement must end with a semicolon after std::endl.
4fill in blank
hardFill both blanks to create a for loop that prints numbers from 1 to 5.
C++
for (int [1] = 1; [2] <= 5; ++[1]) { std::cout << [1] << std::endl; }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using different variable names in initialization and condition.
Forgetting to increment the loop variable.
✗ Incorrect
The loop variable must be the same in initialization and condition to work correctly.
5fill in blank
hardFill all three blanks to declare a function named 'add' that takes two integers and returns their sum.
C++
int [1](int [2], int [3]) { return a + b; }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using parameter names different from 'a' and 'b'.
Naming the function something other than 'add'.
✗ Incorrect
The function name is 'add', and the parameters are 'a' and 'b' to match the return statement.