0
0
C++programming~10 mins

Why variables are needed in C++ - Test Your Understanding

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to declare an integer variable named age.

C++
int [1];
Drag options to blanks, or click blank then click option'
A5
Bcout
Cage
Dmain
Attempts:
3 left
💡 Hint
Common Mistakes
Using a number instead of a variable name.
Using reserved words like 'main' or 'cout' as variable names.
2fill in blank
medium

Complete 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'
A!=
B==
C+=
D=
Attempts:
3 left
💡 Hint
Common Mistakes
Using '==' instead of '=' for assignment.
Using '+=' when just assigning a value.
3fill in blank
hard

Fix 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'
Anum
B5.5
Cnumber
Ddouble
Attempts:
3 left
💡 Hint
Common Mistakes
Using a number as a variable name.
Using a type name like 'double' as a variable name.
4fill in blank
hard

Fill 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'
Aint
Bfloat
Ccount
Dtotal
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping type and variable name.
Using a type name as a variable name.
5fill in blank
hard

Fill 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'
Afloat
Bpi
Dint
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'int' for decimal values.
Printing a variable name different from the declared one.