Does anyone know how to write this right? This is for a coding class and I’m super confused on it.

First activity:

1. Declare three variables: firstSnack,
second Snack, and thirdSnack.
Assign the name of a snack (as a string)
to each variable.

2. Declare another variable and call it
bestSnack.
Assign a value to bestSnack USING THE
NAME OF ONE OF THE ABOVE VARIABLES.
Do not use a string directly.

3. Now, change your mind! Reassign the value
of bestSnack, again using the variable name,
not the string. (THIS SHOULD BE DONE ON
A NEW LINE)

Second activity:

4. Declare three variables and give them the names of three common grocery items. Assign to each variable a NUMBER value approximately its price. Don’t use $ sign, just the actual number.

5. Declare another variable, name it total, and assign to it the SUM of the three other variables, contain. Hint - you’ll need to use an arithmetic operator to do this.

Respuesta :

Answer:

This is using c++ syntax, you might need to make slight adjustment for other languages.

First activity:

string firstSnack = "chips";

string secondSnack = "pizza";

string thirdSnack = "apples";

string bestSnack =  firstSnack;

bestSnack = secondSnack;

Second activity:

double apple = 0.5;

double banana = 0.75;

double orange = 1.43;

double total = apple + banana + orange;

Explanation:

When first declaring a variable, you want to specify the type (such as int, double, string, bool, etc.) and then the name. You can set the variable value in the declaration, or you can set it to a value later in the program by not having the equals sign and whatever comes next.