© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•2y ago•
70 replies
Mary Cooper

✅ Beginner loop

I need to make it so if the user doesnt enter an integer it gives an error.
ive done this but if they enter 'cat' the error only shows up for a a split second and then the program closes.

do
{
try
{
Console.WriteLine();
Console.Write("Input test score: ");
testscore = Convert.ToInt32(Console.ReadLine());
}
catch
{
Console.WriteLine("Invalid Integer... Press Enter To Exit.");
Console.ReadLine();
return;
}


if (testscore == -1)
{
Console.Write("Well done, Pres ENTER To Exit....");
Console.ReadLine();
Console.WriteLine();
Environment.Exit(0);
}

else if (testscore < -1)
{
Console.WriteLine("Invalid Integer. Please Retry");
}

else if (testscore > 100)
{
Console.WriteLine("Invalid. Please Enter Your Test Score.");
}


else if (testscore >= 0 && testscore <= 49)
{
Console.WriteLine("You need to put in more work!");
}
else if (testscore >= 50 && testscore <= 79)
{
Console.WriteLine("Could you do better? ");
}

else if (testscore >= 80 && testscore <= 100)
{
Console.WriteLine("Well Done!");
}
} while (true);

}
}
}
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources
Was this page helpful?

Similar Threads

Recent Announcements
Next page

Similar Threads

❔ Loop problem, beginner difficulty
C#CC# / help
3y ago
✅ Arrays and Foreach Loop - Beginner
C#CC# / help
3y ago
✅ beginner
C#CC# / help
3y ago