exceptions

Updated on November 27, 2017 in [C] Beginner
Share on Facebook0Tweet about this on TwitterShare on Google+0Share on Reddit0
0 on November 27, 2017

I’m trying to implement an exception to get my program to continue to run even if double.parse tries to parse say “fred” instead of 1 or 2. Here’s what I’ve got so far.

do
{
Console.WriteLine(“Would you like a short-sleeved or long-sleeved shirt? Press 1 for short and 2 for long”); // Presenting customer options for type of shirt.
lengthshirtString = Console.ReadLine(); //customer types number of type of shirt he/she prefers.
lshirt = double.Parse(lengthshirtString);

keepLooping = true;

if (lshirt == 1)
{
Console.WriteLine(“Your shirt would be short sleeved.”);
keepLooping = false;
}

if (lshirt == 2)
{
Console.WriteLine(“Your shirt would be long sleeved.”);
keepLooping = false;
}

if (lshirt > 3 || lshirt < 0)
{
Console.WriteLine(“Please try again!”);
keepLooping = true;
}

} while (keepLooping);

 

I would appreciate if anyone could help.. thank you!

  • Liked by
Reply