程序說明oop
做爲一個掃雷愛好者,今天忽然想作一個腳本,看看本身還剩下多少局才能讓勝率增加1個百分點ui
腳本經過已玩遊戲數和已勝遊戲數,推算還須要連勝多少局遊戲才能讓本身的獲勝率增加一個百分點code
獲勝率是已勝遊戲除以已玩遊戲的商精確到小數點後兩位後乘以百分之百,小數點後兩位之後的數字所有捨去orm
好比72/359=0.20055710306407,所以當前的獲勝率是20%遊戲
贏一局,勝率爲73/360 = 0.20277777777778→勝率20%ip
贏兩局,勝率爲74/361 = 0.20498614958449→勝率20%ci
贏三局,勝率爲75/362 = 0.20718232044199→勝率20%it
贏四局,勝率爲76/363 = 0.20936639118457→勝率20%io
贏五局,勝率爲77/364 = 0.21153846153846→勝率21%form
所以,以當前狀態再連勝5局,就能夠讓勝率增加到21%
在兩個InputBox中輸入359和72後,腳本會提示這樣一個MsgBox
須要注意的是
1)若是不是全勝,那麼勝率是沒法達到100%的,也就是若是有失敗場次,99%就是最高勝率了
2)VBS腳本經過InputBox輸入的數字,要先通過IsNumeric判斷,再通過CInt轉換爲數字,才能放心使用
腳本代碼
Option Explicit 'On Error Resume Next Dim Input1 : Input1 = InputBox("已玩遊戲數", "輸入參數1", VbOKOnly) Dim Input2 : Input2 = InputBox("已勝遊戲數", "輸入參數1", VbOKOnly) '輸入合法性檢驗 If Not IsNumeric(Input1) Or Not IsNumeric(Input2) Then MsgBox "輸入非法,應爲數字", VbOKOnly + VbCritical, "警告" Wscript.Quit End If Dim GamePlayed : GamePlayed = CInt(Input1) Dim GameWon : GameWon = CInt(Input2) If GamePlayed <= 0 Or GameWon < 0 Then MsgBox "已勝遊戲數應不小於0,已玩遊戲數應大於0", VbOKOnly + VbExclamation , "警告" Wscript.Quit End If If GamePlayed < GameWon Then MsgBox GamePlayed & "<" & GameWon MsgBox "已勝遊戲數應小於等於已玩遊戲數", VbOKOnly + VbCritical, "警告" Wscript.Quit ElseIf GamePlayed = GameWon Then MsgBox "勝率到了100%", VbOKOnly + VbInformation, "通知" Wscript.Quit ElseIf GameWon * 100 \ GamePlayed = 99 Then MsgBox "勝率到了99%,你的勝率沒法增加了", VbOKOnly + VbInformation, "通知" Wscript.Quit End If '模擬玩一局贏一局的過程 Dim Counter : Counter = 1 Do If (GameWon + Counter - 1) * 100 \ (GamePlayed + Counter - 1) < _ (GameWon + Counter) * 100 \ (GamePlayed + Counter) Then Exit Do Else Counter = Counter + 1 End If Loop MsgBox "還須要贏" & Counter & "局才能提高1%勝率", VbOKOnly + VbInformation, "通知" Wscript.Quit
END