File tree Expand file tree Collapse file tree 1 file changed +6
-1
lines changed
PrincessBrideTrivia/PrincessBrideTrivia Expand file tree Collapse file tree 1 file changed +6
-1
lines changed Original file line number Diff line number Diff line change @@ -85,7 +85,12 @@ public static string RemovePunctuation(string input)
85
85
public static bool DisplayHardResult ( string userGuess , Question question )
86
86
{
87
87
string normalizedGuess = RemovePunctuation ( userGuess ) . Trim ( ) ;
88
- string normalizedAnswer = RemovePunctuation ( question . Answers [ int . Parse ( question . CorrectAnswerIndex ) - 1 ] ) . Trim ( ) ;
88
+ if ( ! int . TryParse ( question . CorrectAnswerIndex , out int index ) || index < 1 || index > question . Answers . Length )
89
+ {
90
+ Console . WriteLine ( "Incorrect" ) ;
91
+ return false ;
92
+ }
93
+ string normalizedAnswer = RemovePunctuation ( question . Answers [ index - 1 ] ) . Trim ( ) ;
89
94
90
95
if ( String . Equals ( normalizedGuess , normalizedAnswer , StringComparison . OrdinalIgnoreCase ) )
91
96
{
You can’t perform that action at this time.
0 commit comments