Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to print "Hello, World!" using cout.
C++
#include <iostream> int main() { std::[1] << "Hello, World!" << std::endl; return 0; }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'cin' instead of 'cout' for output.
Using 'cerr' which is for error output, not normal output.
✗ Incorrect
The cout object is used to output text to the console in C++.
2fill in blank
mediumComplete the code to print the value of variable x using cout.
C++
#include <iostream> int main() { int x = 5; std::cout << "Value: " << [1] << std::endl; return 0; }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Putting the variable name in quotes, which prints the text instead of the value.
Using a number directly instead of the variable.
✗ Incorrect
To print the value of a variable, use its name without quotes.
3fill in blank
hardFix the error in the code to correctly print "Sum: 15" using cout.
C++
#include <iostream> int main() { int a = 7, b = 8; std::cout << "Sum: " [1] a + b << std::endl; return 0; }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '+' instead of '<<' between string and variables.
Using '>>' which is for input, not output.
✗ Incorrect
The insertion operator << is needed to send multiple parts to cout.
4fill in blank
hardFill both blanks to print the product of a and b with a message.
C++
#include <iostream> int main() { int a = 4, b = 6; std::cout [1] "Product: " [2] a * b << std::endl; return 0; }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '+' or '*' operators instead of '<<' for output chaining.
Using '>>' which is for input.
✗ Incorrect
Use the insertion operator << to send both the string and the product to cout.
5fill in blank
hardFill all three blanks to print the sum and difference of x and y.
C++
#include <iostream> int main() { int x = 10, y = 3; std::cout [1] "Sum: " [2] x + y << ", Difference: " [3] x - y << std::endl; return 0; }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '+' instead of '<<' for output chaining.
Using '>>' which is for input.
Not adding numbers correctly.
✗ Incorrect
Use << to send strings and results to cout.