Reputation: 11
I'm doing this program for a class; I have a listbox
with values from 0-10 which are 'scores' which get recorded every time the user selects a new score (and clicks the button of course). I need to do the following;
get the total scores (this is what's giving me trouble)
here's the code I have for this so far :
intScore = Convert.ToDecimal(lstScores.SelectedItem)
'the counter and accumulator
intTotal = intTotal + 1
decScoreAccumulator += intScore
' here's what calculates the average
If intScore > 0 Then
decScorAvg = decScoreAccumulator / intTotal
End If
Here's an image of it : https://i.sstatic.net/aomQO.png
The number and average I can get to work, since its just using the accumulator and the counter. But no matter what I do, I can't add the values selected for the total. So does anyone know how I can get it to give me total of all the selected scores?
Upvotes: 1
Views: 100
Reputation: 2758
You're code looks good, and you look like your doing everything correctly. You even already have the total in your current code:
decScoreAccumulator += intScore
Because you're adding the score each time to decScoreAccumulator
, this variable has the total you're looking for (assuming it's not confined to the scope of the button click). HTH. Good luck!
Upvotes: 1