I need some help writing ten(10) input numbers to a text file, and displaying the average in the program, with the two lowest numbers dropped. The project is supposed to allow a user to input 10 number scores and the program will display the average of the scores with the 2 lowest dropped, and write the 10 scores to a text file to display.
The problem is I cant get it to display the average correctly
Here is my code so far
Any help is appreciated
Code:Private Sub btnEnterTemp_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEnterTemp.Click ' This button accepts and displays up to 10 Scores from user ' then calculates and displays the average score, with 2 lowest dropped, and writes to a TXT file Dim strScores As String Dim decAverage As Decimal Dim decTotalOfAllScores As Decimal = 0 Dim strInputMessage As String = "Enter Project score #" Dim strInputHeading As String = "Project Score" Dim strNormalMessage As String = "Enter the Project Score #" Dim strNonNumericError As String = "Error- Enter a Number for Project #" Dim strNegativeError As String = "Error- Enter a Positive Number #" Dim strProjectScore(10) As String Dim objWriter As New IO.StreamWriter("scores.txt") Dim intCount As Integer For intCount = 0 To (strProjectScore.Length - 1) strProjectScore(intCount) = InputBox("Please enter score") If IO.File.Exists("scores.txt") Then objWriter.WriteLine(strProjectScore(intCount)) Else MsgBox("File not available") Close() End If Next objWriter.Close() ' Loop Variables Dim strCancelClick As String = "" Dim intMaxNumberOfEntries As Integer = 10 Dim intNumberOfEntries As Integer = 1 ' This loop allows the user to enter up to 10 grades. ' The loop terminates when the user has entered 10 grades or the user ' clicks the Cancel or Close Button in the input box. strScores = InputBox(strInputMessage & intNumberOfEntries, strInputHeading, "") 'Makes label visible lblAverageTemps.Visible = True ' Calculates and displays the Average Scores If intCount > 1 Then decAverage = decTotalOfAllScores / (intNumberOfEntries - 1) lblAverageTemps.Text = "Average project score is " & _ decAverage.ToString("F1") Else lblAverageTemps.Text = "No score Entered" End If 'Disables Enter Temp Button btnEnterTemp.Enabled = False End Sub




Reply With Quote