Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to assign the value 10 to the variable x.
C++
int x [1] 10;
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '+=' instead of '=' will add to the existing value instead of assigning.
Using '*=' or '-=' will perform multiplication or subtraction assignment, not simple assignment.
✗ Incorrect
The assignment operator
= assigns the value on the right to the variable on the left.2fill in blank
mediumComplete the code to add 5 to the variable count using an assignment operator.
C++
count [1] 5;
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '=' will overwrite the value instead of adding.
Using '-=' or '*=' will subtract or multiply instead of adding.
✗ Incorrect
The
+= operator adds the right value to the variable and assigns the result back to it.3fill in blank
hardFix the error in the code to multiply total by 3 using an assignment operator.
C++
total [1] 3;
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '=' will overwrite the value instead of multiplying.
Using '+=' or '-=' will add or subtract instead of multiplying.
✗ Incorrect
The
*= operator multiplies the variable by the right value and assigns the result back.4fill in blank
hardComplete the code to subtract 4 from score and assign the result back.
C++
score [1] 4 ;
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '+=' will add instead of subtract.
Forgetting the semicolon causes a syntax error.
✗ Incorrect
The
-= operator subtracts and assigns, and the semicolon ends the statement.5fill in blank
hardFill both blanks to divide value by 2 and assign the result back, then print it.
C++
value [1] 2 ; std::cout [2] value << std::endl;
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '=' instead of '/=' will overwrite without dividing.
Forgetting semicolons causes syntax errors.
Using '=' instead of '<<' for printing causes errors.
✗ Incorrect
Use
/= to divide and assign, end the first statement with ;, and use << to print.