所以我正在开发一个程序,它会询问作业的数量,比如 20,然后运行一个循环,多次询问每个作业获得的总分以及获得最终成绩的总分。例如,如果用户提交了 2 个作业,作业 1 获得 48 分(满分 50),作业 2 获得 35 分(满分 40),程序将显示成绩为 92。
到目前为止,这是我所拥有的:
Public Class Form1
Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
Me.Close()
End Sub
Private Sub btnCalculate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalculate.Click
Dim amountAssignments As Integer
Dim pointsEarned As Integer = 0
Dim pointsEarnedTotal As Integer = 0
Dim pointsPossible As Integer = 0
Dim pointsPossibleTotal As Integer = 0
Dim Assignment As Integer = 1
Integer.TryParse(txtAmount.Text, amountAssignments)
Do Until Assignment > amountAssignments
txtAmount.Text = String.Empty
lblAmount.Text = "Enter Points Given on Assignment " & Assignment & ":"
Integer.TryParse(txtAmount.Text, pointsEarned)
pointsEarnedTotal = pointsEarnedTotal + pointsEarned
lblAmount.Text = "Enter Points Possible on Assignment " & Assignment & ":"
Integer.TryParse(txtAmount.Text, pointsPossible)
pointsPossibleTotal = pointsPossibleTotal + pointsPossible
Assignment = Assignment + 1
Loop
lblAmount.Text = "Enter the amount of Assignments: "
lblGrade.Text = (pointsEarnedTotal / pointsPossibleTotal)
End Sub
End Class
语法是正确的,但是当程序运行并且输入的作业数量和计算输入时,程序将成绩显示为 NaN,无需其他输入。
可以用另一只眼睛来查看这个并告诉我我在逻辑上搞砸了哪里。
先感谢您!