Reputation: 103
I am working on a project to improve my logic skills that calculates a Quarterbacks passer rating. I have tries all my skills at debugging this problem and I am still at a loss. First I will show you a look at my code.
'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)
I believe that the mathematical logic is true and correct and I also believe that all my datatype conversions are accurate. now I will give you to quarterback rating formula for players in the NFL from their website.
For example, take Steve Young's record-setting season in 1994 when he completed 324 of 461 passes for 3,969 yards, 35 touchdowns, and 10 interceptions.
The four calculations would be:
I have tested this problem and isolated it down to this:
If I input:
Attempt: 469
Completions: 281
Yards: 1406
Touchdowns: 17
Interceptions: 15
However if I input this:
Attempts: 469
Completions: 281
Yards: 1407
Touchdowns: 17
Interceptions: 15
I receive an error that states:
Runtime error - Type Mismatch 'String""
The line cursor error that comes up is on the passerRating
variable line.
Does anyone have an idea as to what I should do to fix this problem?
Upvotes: 1
Views: 405
Reputation: 200193
Don't use FormatNumber
if you want to use the number for further calculations. The purpose of the function is to produce a formatted string representation of the number for output. Remove the else branches:
if ... then
formX = 2.375
else
formX = FormatNumber(formX, 3)
end if
Upvotes: 1