# using for loops to determine highest above average

Page 1 of 1

## 4 Replies - 1090 Views - Last Post: 16 July 2014 - 11:20 AMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=350436&amp;s=dc68a3ad604765ef1632e6ca27cd177d&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 stinkytotoro

Reputation: 0
• Posts: 53
• Joined: 31-May 14

# using for loops to determine highest above average

Posted 15 July 2014 - 08:47 PM

Ask the user to enter a number of scores one at a time and record the scores into the list of scores. See the figure below. When the Calculate button is clicked, the average score is calculated, the number of scores above the average is counted, and the scores above the average are added to the list box on the right.

```   Private Sub btnRecord_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRecord.Click
txtEnter.Clear()
txtEnter.Focus()
End Sub

Private Sub btnAvg_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAvg.Click
Dim sum As Double = 0
Dim avg As Double = 0
Dim high As Double = 0
If lstListScores.Items.Count > 0 Then
For i As Integer = 0 To lstListScores.Items.Count - 1
sum += CDbl(lstListScores.Items(i))
avg = sum / lstListScores.Items.Count

If CDbl(lstListScores.Items(i)) >= avg Then
high = CDbl(lstListScores.Items(i))
End If
Next
txtAvg.Text = avg.ToString("N")

End If
End Sub
End Class

```

I cannot figure out how to display the numbers above average in the second listBox and cannot figure out how to count how many of them there are, any help

Is This A Good Question/Topic? 0

## Replies To: using for loops to determine highest above average

### #2 andrewsw

• blow up my boots

Reputation: 6541
• Posts: 26,470
• Joined: 12-December 12

## Re: using for loops to determine highest above average

Posted 15 July 2014 - 10:09 PM

Quote

I cannot figure out how to display the numbers above average in the second listBox

Doesn't your code already do this? If not, what does it do?

You are already summing and averaging, why is counting so different? What have you tried?
This is your code isn't it?

### #3 stinkytotoro

Reputation: 0
• Posts: 53
• Joined: 31-May 14

## Re: using for loops to determine highest above average

Posted 16 July 2014 - 08:56 AM

``` If CDbl(lstListScores.Items(i)) >= avg Then
high = CDbl(lstListScores.Items(i))
End If

```

this is what I am trying to use to put the scores that are above average into the second list box and it doesnt work
the picture I uploaded is what my code should be doing
when I input numbers I get them in the first list box, I am able to get the average
but I cannot figure out how to record the numbers above average to get them into the second list box

This post has been edited by andrewsw: 16 July 2014 - 10:25 AM
Reason for edit:: Removed previous quote, just press REPLY

### #4 stinkytotoro

Reputation: 0
• Posts: 53
• Joined: 31-May 14

## Re: using for loops to determine highest above average

Posted 16 July 2014 - 11:15 AM

```    Private Sub btnRecord_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRecord.Click
txtEnter.Clear()
txtEnter.Focus()
End Sub

Private Sub btnAvg_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAvg.Click
Dim sum As Double = 0
Dim sumabove As Double = 0
Dim high As Double = 0
Dim avg As Double = 0
If lstListScores.Items.Count > 0 Then
For i As Integer = 0 To lstListScores.Items.Count - 1
sum += CDbl(lstListScores.Items(i))
avg = sum / lstListScores.Items.Count
For k = avg To 100
If CDbl(lstListScores.Items(i)) > avg Then
End If
sumabove = CDbl(lstScoresAbove.Items.Count)
Next

Next
txtAvg.Text = avg.ToString("N")
txtAboveAvg.Text = sumabove.ToString("N")
End If
End Sub
End Class

```

updated, still trying to figure out how to get the numbers above average into the list box so I can them count them

### #5 Oppemaj

Reputation: 23
• Posts: 94
• Joined: 15-November 13

## Re: using for loops to determine highest above average

Posted 16 July 2014 - 11:20 AM

This is how you could do it:

``` Dim counter As Integer = 0
lstScoresAbove.Items.Clear()
For Each number As Double In lstListScores.Items
If number > avg Then
counter += 1
high = number