Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to print "Hello, C++!" to the console.
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.
Trying to print without std::cout.
✗ 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 'age' with value 25.
C++
int [1] = 25;
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a wrong variable name.
Trying to declare type twice.
✗ Incorrect
Variable name should be 'age' as requested.
3fill in blank
hardFix the error in the code to correctly return 0 from main.
C++
int main() {
return [1];
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Returning a string instead of an integer.
Returning a non-zero value.
✗ Incorrect
The return value must be the integer 0, not a string or other value.
4fill in blank
hardFill both blanks to declare a float variable 'pi' with value 3.14.
C++
[1] [2] = 3.14;
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using int type for decimal values.
Wrong variable name.
✗ Incorrect
Use 'float' as type and 'pi' as variable name.
5fill in blank
hardFill all three blanks to create a simple if statement that prints "Yes" if x is greater than 10.
C++
#include <iostream> int main() { int x = 15; if (x [1] [2]) { std::cout << [3] << std::endl; } return 0; }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong comparison operator.
Forgetting quotes around the string.
✗ Incorrect
The condition is 'x > 10' and the printed text is "Yes".