Skip to content

Commit

Permalink
Merge pull request #34 from mmoomocow/mmoomocow/issue33
Browse files Browse the repository at this point in the history
Check user answer is a valid answer
  • Loading branch information
mmoomocow authored Sep 18, 2021
2 parents 12cc00f + 11e76a4 commit 1bb4664
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions console/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ static void Main(string[] args)
// Pre-define an int for the answer outside of the scope of the while loop
int answerInt;
// Another while loop used for input, for the same reasons as above
while (!Int32.TryParse(Console.ReadLine(), out answerInt))
while (!Int32.TryParse(Console.ReadLine(), out answerInt) && answerInt <= 1 && answerInt >= 4)
{
// Tell the user that their answer is not valid, and to try again
Console.WriteLine("Thats not a valid answer, please try again!");
Expand Down Expand Up @@ -263,17 +263,17 @@ static void Main(string[] args)
Console.WriteLine("You got non correct, but you can only go up from here");
}
// If they got more than 75%
else if (userScore <= (numberOfQuestions * 0.75))
else if (userScore >= (numberOfQuestions * 0.75))
{
Console.WriteLine($"Amazing! You got {userScore}/{numberOfQuestions} correct. Can you get them all next time?");
}
// If they got more than 50%
else if (userScore <= (numberOfQuestions * 0.5))
else if (userScore >= (numberOfQuestions * 0.5))
{
Console.WriteLine($"Pretty good, you got {userScore}/{numberOfQuestions}. Can you do better?");
}
// If they got more than 25%
else if (userScore <= (numberOfQuestions * 0.25))
else if (userScore >= (numberOfQuestions * 0.25))
{
Console.WriteLine($"Not bad, but only {userScore}/{numberOfQuestions} correct, ");
}
Expand Down

0 comments on commit 1bb4664

Please sign in to comment.