Stone
Lv 6
Stone 發問時間: 電腦與網際網路程式設計 · 2 0 年前

幫我加註解...VB

Me.AutoRedraw = TrueDim arr(9) As IntegerDim avg As Double, sum As Integer, max As Integer, min As Integer, i As Integer, cnt As IntegerFor i = 0 To 9arr(i) = Val(InputBox("請輸入第" & i + 1 & "位評審給的得分"))Print "第" & i + 1 & "位評審的評分為" & arr(i)Nextmin = arr(0)max = arr(0)cnt = 0For i = 0 To 9If arr(i) < min Then min = arr(i)If arr(i) > max Then max = arr(i)NextPrint "最高評分為 : " & maxPrint "最低評分為 : " & minFor i = 0 To 9If arr(i) <> min And arr(i) <> max Thencnt = cnt + 1sum = sum + arr(i)End IfNextavg = sum / cntPrint "平均評分為 : " & avg

1 個解答

評分
  • ?
    Lv 6
    2 0 年前
    最佳解答

    Me.AutoRedraw = True 'autoredraw設為true,這樣每個print都會出現Dim arr(9) As Integer '設陣列'宣告會用到的變數Dim avg As Double, sum As Integer, max As Integer, min As Integer, i As Integer, cnt As Integer'用for,取得10位評審給分,並同時印出For i = 0 To 9arr(i) = Val(InputBox("請輸入第" & i + 1 & "位評審給的得分"))Print "第" & i + 1 & "位評審的評分為" & arr(i)Next'此段為取得十位評分最的最高,與最低分'先假設第一個元素為最大值與最小值min = arr(0)max = arr(0)cnt = 0For i = 0 To 9 '以for迴圈來比對每一個元素If arr(i) < min Then min = arr(i) '如果目前元素比目前最小值小,取代之If arr(i) > max Then max = arr(i)'如果目前元素比目前最大值大,取代之Next'印出上述程序所得之最大與最小值Print "最高評分為 : " & maxPrint "最低評分為 : " & min'加總十個評分,但不包括最大值與最小值For i = 0 To 9If arr(i) <> min And arr(i) <> max Thencnt = cnt + 1sum = sum + arr(i)End IfNextavg = sum / cnt '求不含大小值的平均Print "平均評分為 : " & avg

還有問題?馬上發問,尋求解答。