What I have is below, and what I need to add are the Visual Basic statements as
ID: 3762745 • Letter: W
Question
What I have is below, and what I need to add are the Visual Basic statements as indicated by the comments. Once that is done, execute the source code using the following 10 values. 45000, 22000, 6000, 100000, 57000, 1000, 90000, 12000, 6000, and 35000. The minimum value should be 1000, and the maximum value should be 100000. The average value should be 37400.
I keep getting errro messages that says "Option Strict on disallows implicit conversion from Double to Integer
Option Explicit On
Option Strict On
Module MinMaxSalary
Sub Main()
' Declare a named constant for array size here
Const MAX_SALARIES As Double = 10
' Declare array here
Dim salaries(MAX_SALARIES) As Double
' Use this integer variable as your loop index
Dim loopIndex As Integer
' Use this variable to store the salary input by user
Dim salary As Double
' Declare string version of salary here
Dim salaryString As String
' Use these variables to store the minimum and maximum values
Dim min As Double
Dim max As Double
' Use these variables to store the total and the average
Dim total As Double
Dim average As Double
' Write a loop to get salaries from user and assign to array
For loopIndex = 0 To MAX_SALARIES - 1
salaryString = InputBox$("Enter a salary: ")
salary = Convert.ToDouble(salaryString)
' Assign value to array
salaries(loopIndex) = salary
Next loopIndex
' Assign the first element in the array to be the minimum and the maximum
min = salaries(0)
max = salaries(0)
' Start out your total with the value of the first element in the array
total = salaries(0)
' Write a loop here to access array values starting with numbers(1)
For loopIndex = 1 To MAX_SALARIES - 1
' Within the loop test for minimum and maximum salaries
' if current element of salaries array is less than min then
' update min to current element
If salaries is < min Then
min = salaries
End If
' if current element of salaries array is greater than max then
' update max to current element
If salaries is > max Then
max = salaries
End If
' Also accumulate a total of all salaries
' Add each element of salaries array to total
total = total + salaries
Next loopIndex
' Calculate the average of the 10 salaries
' Total salary divided by number of salaries gives average salary
average = total / 10
' Print the salaries stored in the salaries array
For loopIndex = 0 To MAX_SALARIES - 1
Print salaries(loopIndex)
Next loopIndex
' Print the maximum value, minimum value, and average
Print ("Maximum Salary is ")
Print max
Print ("Minimum Salary is ")
Print min
Print ("Average Salary is ")
Print average
End Sub
End Module
Explanation / Answer
Hello Dear,
You declare
Dim salaries(MAX_SALARIES) As Double at Line No - 8 and,
Dim loopIndex As Integer at Line No -10
and after that
You are using For Loop in Line No - 23 (For loopIndex = 0 To MAX_SALARIES - 1)
So, for Your Kind Information You are using loopIndex(Integer) and MAX_SALARIES(Double) in For Loop
Plz Change the Datatype of MAX_SALARIES, use Integer placce of Double
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.