问题在于我的代码底部,我必须让程序以相反的顺序背诵输入的值。我认为这可能与索引有关?
Option Explicit On Option Strict On
“作者:默里·斯皮尔斯”日期:2012 年 10 月 12 日
'编写一个程序,接受五个输入值并将它们存储到一个数组中。'然后以相反的顺序显示数字。'然后显示平均数,以及所有高于平均数的数。
进口系统
模块值
Sub Main()
Dim Number(4) as Integer
Dim Average as Double = 0
Dim Index as integer
'
For Index = 0 to 4
Console.Write("Enter number: ")
Number(Index)=Convert.ToInt32(Console.Readline())
Next Index
'Figure out the average for all the entered values.
Average = (Number(0)+Number(1)+Number(2)+Number(3)+Number(4))/5
Console.Writeline("The average of the numbers is: " &Average)
Console.Write("Numbers that are greater than the average: ")
Index = 4
Do until Index = 0
If Number(Index) > Average then
Console.Writeline(Number(Index))
End If
Index -=1
Loop
Console.Writeline("Numbers in reverse order: ")
Index = 4
Do while Number(index) > 0
Console.Writeline(Number(Index))
Number(index) -= 1
Loop
End Sub
端模块