所以我正在制定一个程序,要求分配的数量,比如20,然后通过一个循环,多次询问每个作业获得的总分数以及可能获得最终分数的总分数年级。例如,如果用户输入2个作业,其中作业1获得50分中的48分,作业2获得40分中的35分,则该程序将显示成绩为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,而不会请求其他输入。
可以用另一组眼睛来看看这个并告诉我逻辑搞砸的地方。
提前谢谢!
答案 0 :(得分:0)
当循环开始时,该程序似乎没有某种用户干预。我要做的当然是让用户在文本框中输入分配数量然后从那里要求用户输入由斜线分隔的输入框中的标记,例如我输入45/50所以输入后程序找到索引“/”之前的所有字符都是pointsEarned
,可以添加到pointsEarnedTotal
,而'/'后的所有字符都放在pointsPossible
中并添加到pointsPossibleTotal
试试这个并告诉我它是怎么回事......如果它有效,给我点数。
`Private Sub butGetMarks_Click(sender As System.Object,e As System.EventArgs)处理但是GetMarks.Click
Dim赋值为Integer = 0
Dim totalAssignments As Integer
Integer.TryParse(txtAssignments.Text,totalAssignments)
Dim pointsEarned As Double = 0
Dim pointsEarnedTotal As Double = 0
Dim possibleEarned As Double = 0
Dim possibleEarnedTotal As Double = 0
Dim temp As String
For i As Integer = 1 To totalAssignments
temp = InputBox("Enter marks per assignment separated by /")
Dim i1 As Integer
i1 = temp.IndexOf("/") 'read index of /
pointsEarned = temp.Substring(0, i1) 'read from start until / character
possibleEarned = temp.Substring(i1 + 1) 'read from after / character onwards
'add to totals
possibleEarnedTotal += possibleEarned
pointsEarnedTotal += pointsEarned
Next i
MessageBox.Show(pointsEarnedTotal & "/" & possibleEarnedTotal)
End Sub`