decimal total = 0.00m;
char Base;
string bill = "\n\n";
Console.WriteLine("**************");
Console.WriteLine("My Pizza");
Console.WriteLine("\nTraditional or 'thin and crispy' base? ");
Console.WriteLine("A = Traditional");
Console.WriteLine("B = thin and crispy");
Base = char.Parse(((Console.ReadLine()).ToLower()).Substring(0, 1));
switch (Base)
{
case 'a':
bill += "\n\t-Traditional Base selected = FREE";
break;
case 'b':
bill += "\n\t-thin and crispy Base selected = FREE";
break;
}
Console.WriteLine("\n\n\t\t\t=====Bill=====");
Console.WriteLine(bill);
Console.WriteLine("\n\t\ttotal \t\t = £" + total);
Console.ReadLine();
}
}
}
Refactorings
No refactoring yet !
Ants
June 30, 2010, June 30, 2010 17:11, permalink
Doing that makes things really ugly... You should consider having the try-catch around the switch, OR I recommend moving each of the case handlers into their own functions.
Base = char.Parse(((Console.ReadLine()).ToLower()).Substring(0, 1));
switch (Base)
{
case 'a':
{
try
{
bill += "\n\t-Traditional Base selected = FREE";
}
catch (Exception) // Really bad: Should be explicit flavor of exception
{
// handle exception
}
break;
}
case 'b':
{
try
{
bill += "\n\t-thin and crispy Base selected = FREE";
}
catch (Exception) // Really bad: Should be explicit flavor of exception
{
// handle exception
}
break;
}
}
I don't know how to insert a try-catch method onto the switch statement and no matter where I look I never find my answer