I would like to know how to edit the following code to make users enter a number if they enter a string for any of the following prompts.
Console.Write("\nPlease enter a number: ");
double num1 = Convert.ToDouble(Console.ReadLine());
Console.WriteLine("\nPlease enter a operator: ");
string optr = Console.ReadLine();
Console.Write("Please enter a number: ");
double num2 = Convert.ToDouble(Console.ReadLine());
double total;
string end;
do
{
switch (optr)
{
case "+":
total = (num1 + num2);
Console.Write("Total : " + total);
break;
Console.Write("Invalid operator");
break;
}
Console.WriteLine("\n \nDo you want to make another calculation? Yes or No: ");
end = Console.ReadLine();
} while (end != "No");
Console.Write("Press Enter key to exit");
Console.ReadKey();