Alright so im making a program that reads a text file that lists a persons name then next line has the persons test score. I am trying to calculate the standard deviation for any given amount of people. I got the mean calculation to work, but I can't seem to see why my standard deviation calculation doesnt work. Please check it out for me!
Standard Deviation Formula = http://en.wikipedia.org/wiki/Standard_deviationCode:Dim name As String, total, x, n as Double Dim sr As IO.StreamReader = IO.File.OpenText("scores.txt") Dim count As Double = 0 Do While sr.peek <> -1 name = sr.ReadLine total += CDbl(sr.ReadLine) count += 1 Loop Do While sr.Peek <> -1 name = sr.ReadLine x = CDbl(sr.ReadLine) n += ((x - total) ^ 2) Loop ListBoxdata.items.add("Mean = " & Math.Round(total/count, 1)) ListBoxdata.items.add("Standard Deviation = " & Math.Sqrt(n / count)) end sub




Reply With Quote