Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to declare an integer variable named age.
C++
int [1]; Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a number instead of a variable name.
Using reserved words like 'main' or 'cout' as variable names.
✗ Incorrect
The variable name age is used to store an integer value.
2fill in blank
mediumComplete the code to assign the value 10 to the variable score.
C++
score [1] 10;
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '==' instead of '=' for assignment.
Using '+=' when just assigning a value.
✗ Incorrect
The single equals sign = is used to assign a value to a variable.
3fill in blank
hardFix the error in the code to correctly declare and initialize a variable.
C++
int [1] = 5.5;
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a number as a variable name.
Using a type name like 'double' as a variable name.
✗ Incorrect
The variable name should be a valid identifier like num. The value 5.5 is a double, but here we focus on the variable name.
4fill in blank
hardFill both blanks to declare a variable and assign it a value.
C++
[1] [2] = 20;
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping type and variable name.
Using a type name as a variable name.
✗ Incorrect
We declare an integer variable named count and assign it the value 20.
5fill in blank
hardFill all three blanks to declare a float variable, assign a value, and print it.
C++
#include <iostream> using namespace std; int main() { [1] [2] = 3.14f; cout << [3] << endl; return 0; }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'int' for decimal values.
Printing a variable name different from the declared one.
✗ Incorrect
We declare a float variable pi, assign 3.14, and print pi.