我有这个代码,我花了太多时间,我无法想象。它应该得到数字的平均值,然后输出答案。我输入名称然后当我输入数字时它只需要1,然后我就无法继续。我是一个小基础的初学者,我很难理解这一点。我知道视觉基础更先进,所以我试图在进入visual basic之前理解简单的东西。如果我能得到一些建议,我将不胜感激。
total=0
count=0
TextWindow.WriteLine("What is the students name? :")
name=TextWindow.Read()
While name<>""
TextWindow.Write(" Enter the grades :")
grades=textwindow.ReadNumber()
While grades<>""
total= total+grades
count=count+1
EndWhile
TextWindow.Write(name+ "average is" +total/grades)
TextWindow.WriteLine("Enter the name of another student or press enter to exit :")
name=textwindow.Read()
答案 0 :(得分:1)
我无法测试atm,但我认为你在代码末尾缺少一个EndWhile。 (你使用2个循环,但只有1个结束)
答案 1 :(得分:0)
你确实需要一段时间,但不要使用秒 - 这会导致无限循环。 我已经为你修改了代码:
total=0
count=0
TextWindow.WriteLine("What is the students name? :")
name = TextWindow.Read()
While name<>""
TextWindow.Write(" Enter the grades :")
grades = textwindow.ReadNumber()
If grades > 0 Then
total= total+grades
count=count+1
Else
Goto end
EndIf
EndWhile
end:
TextWindow.WriteLine(name+ " average is " +total/count)
TextWindow.WriteLine("Enter the name of another student or press enter to exit :")
name = textwindow.Read()
希望这有帮助。
答案 2 :(得分:0)
我已经解决了你的问题!而不是无限等待等级小于0来显示平均值。如果计数等于3(3个学期(从学校开始),我给了它一个计数条件。)然后它将停止显示当年学生分数的平均值(3个学期)。
total=0
count=0
TextWindow.WriteLine("What is the students name? :")
name = TextWindow.Read()
While name<>""
TextWindow.Write(" Enter the grades :")
grades = textwindow.ReadNumber()
If grades > 0 Then
total= total+grades
count=count+1
Else
Goto end
EndIf
If count= 3 then
Goto end
EndIf
EndWhile
end:
TextWindow.WriteLine(name+ " average is " +total/count)
TextWindow.WriteLine("Enter the name of another student or press enter to exit :")
name = textwindow.Read()