我正在为“业务编程入门”课做作业。它使用Visual Basic2017。我们必须有一个使用do while循环和if语句跟踪学生成绩的程序。教授要求我们通过在输入框中输入-1来结束循环,但不能将其用于计算中。这是我所拥有的,并且无法正常工作。
Do
'Prompt user for a score
strInput = InputBox("Enter test Score")
If Integer.TryParse(strInput, intTestScore) Then
If intTestScore >= 0 And intTestScore <= 100 Then
'Calculate running totals for each letter grade
If intTestScore >= 93 Then
'Increase student Count A by 1
intStudentCountA += 1
'add intTestScore to current score total A
intTotalA += intTestScore
ElseIf intTestScore >= 90 Then
'Increase student Count A- by 1
intStudentCountAMinus += 1
'add intTestScore to current score total A-
intTotalAMinus += intTestScore
ElseIf intTestScore >= 87 Then
'Increase student Count B+ by 1
intStudentCountBPlus += 1
'add intTestScore to current score total B+
intTotalBPlus += intTestScore
ElseIf intTestScore >= 83 Then
'Increase student Count B by 1
intStudentCountB += 1
'add intTestScore to current score total B
intTotalB += intTestScore
ElseIf intTestScore >= 80 Then
'Increase student Count B- by 1
intStudentCountBMinus += 1
'add intTestScore to current score total B-
intTotalBMinus += intTestScore
ElseIf intTestScore >= 77 Then
'Increase student Count C+ by 1
intStudentCountCPlus += 1
'add intTestScore to current score total C+
intTotalCPlus += intTestScore
ElseIf intTestScore >= 73 Then
'Increase student Count C by 1
intStudentCountC += 1
'add intTestScore to current score total C
intTotalC += intTestScore
ElseIf intTestScore >= 70 Then
'Increase student Count C- by 1
intStudentCountCMinus += 1
'add intTestScore to current score total C-
intTotalCMinus += intTestScore
ElseIf intTestScore >= 67 Then
'Increase student Count D+ by 1
intStudentCountDPlus += 1
'add intTestScore to current score total D+
intTotalDPlus += intTestScore
ElseIf intTestScore >= 63 Then
'Increase student Count D by 1
intStudentCountD += 1
'add intTestScore to current score total D
intTotalD += intTestScore
ElseIf intTestScore >= 60 Then
'Increase student Count D- by 1
intStudentCountDMinus += 1
'add intTestScore to current score total D-
intTotalDMinus += intTestScore
ElseIf intTestScore >= 0 Then
'Increase student Count F by 1
intStudentCountF += 1
'add intTestScore to current score total F
intTotalF += intTestScore
End If
End If
'running total
intTotal += intTestScore
'increase student counter by 1
intStudentCount += 1
'add the score to listbox
lstScore.Items.Add(intTestScore.ToString())
Else
MessageBox.Show("The value must be an integer. The maximum possible score is 100.")
End If
Loop While intTestScore <> -1
我没有包括变量,因为这篇文章真的会很长。我不确定为什么仍在计算-1。有任何想法吗?预先感谢!
答案 0 :(得分:1)
private void parseJsonToList() {
itemss = clusterManagerAlgorithm.getItems();
try {
items.removeAll(itemss);
}catch (IndexOutOfBoundsException e){
Log.d("itemsDoesn't exist"," : ");
}
mClusterManager.clearItems();
mClusterManager.cluster();
mClusterManager.addItems(items);
Log.d("items"," : " + items);
}
循环仅在最后检查条件。
它开始循环的迭代,然后获得测试分数。
public class User {
private final int id;
private final String username;
private final String pwd;
public User(int id, String username, String pwd) {
this.id = id;
this.username = username;
this.pwd = pwd;
}
@Override
public String toString() {
return id + " " + username + " " + pwd;
}
public int getId() {
return id;
}
public String getUsername() {
return username;
}
public String getPwd() {
return pwd;
}
}
然后,它执行循环的主体,直到到达结尾,在那儿它看到得分为Do...While
并退出循环。
另一种写此方法的方法是让循环无限期地运行。
'Prompt user for a score
strInput = InputBox("Enter test Score")
然后检查分数是否为-1
并退出循环。
Do
//Body
Loop While True