这是我必须上交的作业。我遗漏了一些关于函数计算的东西

时间:2014-10-28 08:03:01

标签: vb.net visual-studio-2010

我有三个考试成绩,最低分将被删除。函数用于计算最终成绩,成绩必须从数字转换为字母。我已经做了我想做的一切,并确保功能写得正确。

'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

1 个答案:

答案 0 :(得分:2)

问题在于您将函数调用为变量并比较另一个变量。替换下面的部分并重试;

'this is how i use the function calculation 
result = (SemesterGrade(test1, test2, test3))

'This is to convert the number score to a letter
If result >= 90 Then
    Result1 = ("A")
ElseIfresult >= 80 Then
    Result1 = "B"
ElseIf result  >= 70 Then
    Result1 = "C"
ElseIf result >= 60 Then
    Result1 = "D"
ElseIf result < 60 Then
    Result1 = "F"
End If