Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

in Figure rite a statement that displays the default value of 4.99 in the input

ID: 3604878 • Letter: I

Question

in Figure rite a statement that displays the default value of 4.99 in the input box shown retun value from the InputBox function to a variable named decHappyMeal with the mesd 6-106 and ag 1. Write a Happy Meal with the title Kids Meal. Kids Meal oK Cost of Happy Meal Cancel 39 FIGURE 6-106 2. Write compound operators for the following equations a, int FieldGoal.e intFieldGoal+ 3 b. db!Cube = db!Cube ^ 3 c. strDog= strDog &Treat;" 3. Write For... Next loops that calculate the sum of the following ranges and assign their sum to a variabl named intSum: a. The first 50 numbers starting with 1 b. The even numbers beginning at 10 and ending with 100 c. The numbers 20, 30, 40, 50, 60, and 70 4. Find the errors in the following For...Next header statements: a. For intCounter “1” To “19" b. For intNumber-98 To 71 Step 2 c. For intValue 12 To 52 Step-4 d. For strCount -15 To 5 Step 5

Explanation / Answer

1. Write statement that display the default value of 4.99 in the input box and assigns that return value from the the InputBox function to a variable named decHappyMeal with the message Cost of Happy Meal with the title Kids Meal.

Answer:

Dim decHappyMeal As Decimal

decHappyMeal = InputBox("Cost of Happy Meal", "Kids Meal", 4.99)

2. Write compound operators for the following equations:

a. intFieldGoal = intFieldGoal + 3

Answer: intFieldGoal += 2

b. dblCube = dblCube ^ 3

Answer: dblCube ^= 3

c. strDog = strDog & "Treat"

Answer: strDog &= "Treat"

3. Write For...Next loops that calculate the sum of the following ranges and assign their sum to the variable names intSum:

a. The first 50 numbers starting with 1

Answer:

Dim intSum As Integer = 0

For range = 1 To 50

    intSum = intSum + range

Next

b. The even numbers beginning at 10 and ending with 100

Answer:

Dim intSum As Integer = 0

For range = 10 To 100

    'check if number if even

    If range Mod 2 = 0 Then

         intSum = intSum + range

     End If

Next

c. The numbers 20, 30, 40, 50, 60 and 70

Answer:

Dim intSum As Integer = 0

For range = 20 To 70 Step 10 'each time increment range by 10

    intSum = intSum + range

Next

4. Find the errors in the following For...Next header statements

a. For intCounter = "1" To "19"

Answer: The range of the counter variable must be integer, enclosing 1 and 19 in double quotes make them strings. The correct header is

For intCounter = 1 To 19

b. For intNumber = 98 To 71 Step 2

Answer: The range of the counter variable in the above For..Next is from 98 to 71, and each time we are incrementing intNumber by 2. Increment the value 98 by 2 each time will never lead to 71 as 98 is greater than 71 and hence leads to a infinite loop. If we want the loop to work properly either the loop must have its range from 71 to 98 or it should decrement intNumber. The correct headers are:

For intNumber = 71 To 98 Step 2

                or

For intNumber = 98 To 71 Step -2

c. For intValue = 12 To 52 Step -4

Answer: The range of the counter variable in the above For..Next is from 12 to 52, and each time we are decrementing intValue by 4. Decrementing the value 52 by each time will never lead to 52 as 12 is less than 52 and hence leads to a infinite loop. If we want the loop to work properly we must increment intValue by 4. Here is the correct header

For intValue = 12 to 52 Step 4

d. For strCount = -15 To 5 Step 5

Answer: According to the naming convention of the counter variable it is clear that we are trying to use a string variable as counter variable which is not possible. The counter variable must be an integer variable and using intCount instead of strCount will be correct.

For intCount = -15 To 5 Step 5 (this is the correct header)