Advertisement
imjyb1008

1613122602156_03

Dec 26th, 2013
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Private Sub Command3_Click()
  2. '3.某班學生人數不詳,欲輸入每一個學生的VB成績,當輸入-1 時表示結束輸入,然後計算全班人數?,及格人數?,不及格人數?,及全班平均分數?
  3.    Cls
  4.    
  5.     Dim count As Integer
  6.     Dim good As Integer
  7.     Dim bad As Integer
  8.     Dim sum As Integer
  9.    
  10.     n = InputBox("輸入分數")
  11.    
  12.     Do While n <> -1
  13.    
  14.         sum = sum + n
  15.    
  16.         count = count + 1
  17.        
  18.         If n <= 100 And n >= 60 Then
  19.        
  20.             good = good + 1
  21.        
  22.         ElseIf n >= 0 Then
  23.        
  24.             bad = bad + 1
  25.        
  26.         End If
  27.        
  28.         n = InputBox("輸入分數")
  29.        
  30.     Loop
  31.    
  32.     Print "全班人數為:"; count
  33.     Print "及格人數為:"; good
  34.     Print "不及格人數為:"; bad
  35.     Print "全班平均為:"; sum / count
  36.    
  37. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement