-1
我有三個測試分數,最低分數將被丟棄。函數用於計算最終成績,而成績必須從數字轉換爲字母。我已盡我所能,我試圖弄清楚並確保函數的寫入是正確的。這是我必須交給的任務。我錯過了一些關於函數計算的內容
'I put these at public class so they could be used throughout the program
Dim test1 As Double
Dim test2 As Double
Dim test3 As Double
Dim student As String
Dim Result1 As String
Dim total As String
Function SemesterGrade(ByVal t1 As Double, ByVal t2 As Double, ByVal t3 As Double) As Double
'This function determines the test scores and drops the lowest score from calculation
If t1 < t2 And t1 < t3 Then
total = CStr(((t2 + t3)/2))
ElseIf t2 < t3 And t2 < t1 Then
total = CStr(((test1 + test3)/2))
ElseIf t3 < t2 And t3 < t1 Then
total = CStr(((t1 + t2)/2))
'I added this if statement to calculate if all the scores were the same because the program would not give me the correct output
ElseIf t1 = t2 And t2 = t3 Then
total = CStr((t1 + t2 + t3)/3)
End If
'this returns the result from this function
Return CDbl(total)
End Function
Private Sub btnDetermine_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDetermine.Click
Dim result As String
'these pull the information from my textboxes
test1 = CDbl(txtFirst.Text)
test2 = CDbl(txtSecond.Text)
test3 = CDbl(txtThird.Text)
student = txtName.Text.ToUpper
'this is how i use the function calculation
result = CStr((SemesterGrade(test1, test2, test3)))
'This is to convert the number score to a letter
If CDbl(total) >= 90 Then
Result1 = ("A")
ElseIf CDbl(total) >= 80 Then
Result1 = "B"
ElseIf CDbl(total) >= 70 Then
Result1 = "C"
ElseIf CDbl(total) >= 60 Then
Result1 = "D"
ElseIf CDbl(total) < 60 Then
Result1 = "F"
End If
'This is the output for the result
txtResult.Text = student & ": " & Result1
End Sub
End Class
非常感謝。 – 2014-10-28 08:21:48