English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
所有分類

我要做輸入五個數值並判斷最大值and最小值為何
以下是我做失敗的程式碼,(連著總分平均一起,不要理總分和平均)
告訴我哪裡寫錯了要怎麼改
Private Sub Command15_Click()
Dim score(4) As Single
Dim sum As Single
For I = 0 To 4
score(0) = Text10.Text
score(1) = Text11.Text
score(2) = Text12.Text
score(3) = Text13.Text
score(4) = Text14.Text
sum = sum score(I)
Next I
Average = sum / 5
Cls
For I = 1 To 4
Max = score(0)
If score(I) > Max Then
Max = score(I)
End If
Min = score(0)
If score(I) < Min Then
Min = score(I)
End If
Next I
MsgBox ("總分是" & sum & vbCrLf & "平均是" & Average & vbCrLf & "最高分是" & Max & vbCrLf & "最低分是" & Min)
End Sub

2005-12-28 17:05:49 · 3 個解答 · 發問者 Anonymous in 電腦與網際網路 程式設計

3 個解答

'score(),Max,Min,的初值放錯地方了
Private Sub Command15_Click()
Dim score(4) As Single
Dim sum As Single
score(0) = Text10.Text
score(1) = Text11.Text
score(2) = Text12.Text
score(3) = Text13.Text
score(4) = Text14.Text
For I = 0 To 4
sum = sum + score(I)
Next I
Average = sum / 5
Cls
Max = score(0): Min = score(0)
For I = 1 To 4
If score(I) > Max Then Max = score(I)
If score(I) < Min Then Min = score(I)
Next I
MsgBox ("總分是" & sum & vbCrLf & "平均是" & Average & vbCrLf & "最高分是" & Max & vbCrLf & "最低分是" & Min)
End Sub

2005-12-28 17:51:47 · answer #1 · answered by W.J.S. 7 · 0 0

To 小呆
他是自己先寫過
沒辦法解決才上來問的
這是好現像 ^^

2005-12-29 06:31:12 · answer #2 · answered by ? 5 · 0 0

Private Sub Command15_Click()
Dim score(4) As Single
Dim sum As Single
Dim Max, Min, Average As Single

score(0) = Text10.Text
score(1) = Text11.Text
score(2) = Text12.Text
score(3) = Text13.Text
score(4) = Text14.Text
Max = score(1) '避免所有值都比0小,所以先把第一個值代入
Min = score(1) '避免所有值都比0大,所以先把第一個值代入
For I = 0 To 4
sum = sum+ score(I)
if score(I) > Max Then Max = score(I)
if score(I) < Min Then Min = score(I)
Next I
Average = sum / 5
MsgBox ("總分是" & sum & vbCrLf & "平均是" & Average & vbCrLf & "最高分是" & Max & vbCrLf & "最低分是" & Min)
End Sub

功課還是自己想比較好!

2005-12-28 17:59:15 · answer #3 · answered by 阿賢哥 2 · 0 0

fedest.com, questions and answers