我正在开展一个项目,以提高我的逻辑技能,计算四分卫的传球手评分。我已经尝试了调试这个问题的所有技能,但我仍然处于亏损状态。首先,我将向您展示我的代码。
'Prompt Statements
'error handling to see if the previous 5 prompted inputs are numbers
Wscript.StdOut.WriteLine "Choose a Quarterback : "
QB = Wscript.StdIn.ReadLine
'attempts and completions loop
'attempts
do
Wscript.StdOut.WriteLine "How many attempts did " & QB & " throw: "
attempts = Wscript.StdIn.ReadLine
if IsNumeric(attempts) then
attempts = CInt(attempts)
else
Wscript.StdOut.Write "You did not enter a number. Please try again."
end if
loop while IsNumeric(attempts) = false
'completions
do
do
Wscript.StdOut.WriteLine "How many completed passes did " & QB & " throw for: "
completions = Wscript.StdIn.ReadLine
if IsNumeric(completions) then
completions = CInt(completions)
else
Wscript.StdOut.Write "You did not enter a number. Please try again."
end if
loop while IsNumeric(completions) = false
if attempts < completions then
Wscript.StdOut.Writeline "Completions can not be more that attempts please try again."
else
exit do
end if
loop while attempts < completions
'yards
do
Wscript.StdOut.WriteLine "How many yards did " & QB & " throw for: "
yards = Wscript.StdIn.ReadLine
if IsNumeric(yards) then
if yards <= 32767 then
yards = CInt(yards)
exit do
else
if yards > 32767 then
yards = CLng(yards)
exit do
end if
end if
else
Wscript.StdOut.Write "You did not enter a number. Please try again."
end if
loop while IsNumeric(yards) = False
'touchdowns
do
Wscript.StdOut.WriteLine "How many touchdowns did " & QB & " make: "
touchdowns = Wscript.StdIn.ReadLine
if IsNumeric(touchdowns) then
touchdowns = CInt(touchdowns)
else
Wscript.StdOut.Write "You did not enter a number. Please try again."
end if
loop while IsNumeric(touchdowns) = false
'interceptions
do
Wscript.StdOut.WriteLine "How many interceptions did " & QB & " throw: "
interceptions = Wscript.StdIn.ReadLine
if IsNumeric(interceptions) then
interceptions = CInt(interceptions)
else
Wscript.StdOut.Write "You did not enter a number. Please try again."
end if
loop while IsNumeric(interceptions) = false
'Passer rating formulae
'Percentage of completions formula
formA = (((completions / attempts) * 100) - 30) *.05
if formA < 0 then
formA = 0
else
if formA > 2.375 then
formA = 2.375
else
formA = FormatNumber(formA, 3)
end if
end if
'Average yards gained per attempts formula
formB = ((yards / attempts) - 3) * .25
if formB < 0 then
formB = 0
else
if formB > 2.375 then
formB = 2.375
else
formB = FormatNumber(formB, 3)
end if
end if
'Percentage of touchdowns formula
formC = (touchdowns / attempts) * 20
if formC > 2.375 then
formC = 2.375
else
formC = FormatNumber(formC, 3)
end if
'Percentage of interceptions formula
formD = 2.375 - ((interceptions / attempts) * 25)
if formD < 0 then
formD = 0
else
formD = FormatNumber(formD, 3)
end if
'Summation formula
passerRating = ((formA + formB + formC + formD) / 6) * 100
Wscript.StdOut.WriteLine QB & " has a passer rating of " & FormatNumber(passerRating, 1)
我相信数学逻辑是真实和正确的,我也相信我所有的数据类型转换都是准确的。现在我将根据他们的website给你NFL球员的四分卫评分公式。
例如,1994年史蒂夫·杨创造了创纪录的赛季,当时他完成了461次传球中的324次传球3,969码,35次达阵和10次拦截。
四项计算将是:
我已经测试了这个问题并将其分离到了这个问题:
如果我输入:
Attempt: 469
Completions: 281
Yards: 1406
Touchdowns: 17
Interceptions: 15
但是如果我输入这个:
Attempts: 469
Completions: 281
Yards: 1407
Touchdowns: 17
Interceptions: 15
我收到一条错误消息:
运行时错误 - 类型不匹配&#39;字符串&#34;&#34;
出现的行光标错误位于passerRating
变量行。
有没有人知道我应该怎么做才能解决这个问题?
答案 0 :(得分:1)
如果您想使用该号码进行进一步计算,请不要使用FormatNumber
。该函数的目的是生成输出数字的格式化字符串表示。删除else分支:
if ... then
formX = 2.375
else
formX = FormatNumber(formX, 3)
end if