Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to call the function greet.
C++
#include <iostream> void greet() { std::cout << "Hello!" << std::endl; } int main() { [1]; return 0; }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting the parentheses when calling the function.
Trying to call the function with extra words like 'call'.
✗ Incorrect
To call a function in C++, you write its name followed by parentheses, like
greet().2fill in blank
mediumComplete the code to call the function add with arguments 5 and 3.
C++
#include <iostream> int add(int a, int b) { return a + b; } int main() { int result = [1]; std::cout << result << std::endl; return 0; }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Omitting parentheses or commas between arguments.
Using semicolons or spaces instead of commas.
✗ Incorrect
To call a function with arguments, write the function name followed by parentheses containing the arguments separated by commas, like
add(5, 3).3fill in blank
hardFix the error in calling the function multiply with arguments 4 and 7.
C++
#include <iostream> int multiply(int x, int y) { return x * y; } int main() { int product = [1]; std::cout << product << std::endl; return 0; }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using spaces or semicolons instead of commas between arguments.
Omitting parentheses around arguments.
✗ Incorrect
The correct way to call a function with two arguments is to separate them with a comma inside parentheses:
multiply(4, 7).4fill in blank
hardFill both blanks to call divide with arguments 10 and 2, and store the result.
C++
#include <iostream> double divide(double a, double b) { return a / b; } int main() { double result = [1]; std::cout << [2] << std::endl; return 0; }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Trying to print the function call directly instead of the stored result.
Using spaces instead of commas between arguments.
✗ Incorrect
You call the function with
divide(10, 2) and print the stored variable result.5fill in blank
hardFill all three blanks to call concat with two strings and print the result.
C++
#include <iostream> #include <string> std::string concat(std::string s1, std::string s2) { return s1 + s2; } int main() { std::string combined = [1]; std::cout << [2] << std::endl; return [3]; }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Omitting commas between string arguments.
Trying to print the function call directly instead of the variable.
Returning a non-zero value from main.
✗ Incorrect
Call the function with two strings separated by a comma, print the stored variable, and return 0 to end the program.