I’m a newbie and this is a simple problem I’ve been stuck on. How do I add numbers from an array in VB 2008?
I’ve filled the array with 10 test scores. I’ve sorted the array in descending order (from highest to lowest).
Now I need to figure out how to add the best 8 scores from my sorted array of 10 test scores.
Here is where I’m stuck so far, with my code:
Option Explicit On
Option Strict On
Module scores
Sub Main()
Dim name As String = ""
Dim studentScoreString As String
Const SIZE As Integer = 10
Dim score(SIZE) As Integer
Dim x As Integer
Dim tempHolder As Integer
Dim numberOfElements As Integer = 0
Dim comparisons As Integer
Dim totalScore As Integer
Dim didSwap As Boolean
Const QUIT As Integer = 999
name = InputBox$("Please enter student's name: ")
x = 0
studentScoreString = InputBox$("Enter a score or " & _
QUIT & " to quit ")
score(x) = Convert.ToInt32(studentScoreString)
x = x + 1
Do While x < SIZE And score(x) <> QUIT
studentScoreString = InputBox$("Enter a score or " _
& QUIT & " to quit ")
score(x) = Convert.ToInt32(studentScoreString)
x = x + 1
Loop
numberOfElements = x
comparisons = numberOfElements - 1
didSwap = True
Do While didSwap = True
x = 0
didSwap = False
Do While x < comparisons
If score(x) < score(x + 1) Then
tempHolder = score(x + 1)
score(x + 1) = score(x)
score(x) = tempHolder
didSwap = True
End If
x = x + 1
Loop
comparisons = comparisons - 1
Loop
???? For x = 0 To 7
totalScore = x + 1
Next x
System.Console.WriteLine("The cumulative points of the " _
& "highest eight quiz scores for " _
& name & " are " & totalScore)
System.Console.ReadLine()
End Sub
End Module
Thank you for any help!