例如,当我的程序要求输入一个数字并且我输入一个字母时,程序退出。那么当输入一个字母时,我怎样才能让它什么都不做呢?我用'int'或'strings'看到了这个,但没有用'doubles'看到它真的让我很难过,我不太明白这些是如何修复的
static void Main(string[] args)
{
Console.WriteLine("type 'Exit' to leave this program.");
Console.ReadLine();
Console.Clear();
Valuechoice: Console.WriteLine("Please choose a number.");
double value1 = Convert.ToDouble(Console.ReadLine());
Console.WriteLine("Please choose a second Number.");
double value2 = Convert.ToDouble(Console.ReadLine());
Console.WriteLine("What would you like to do to these numbeers?");
Console.WriteLine("Multiply");
Console.WriteLine("Divide");
Console.WriteLine("Add");
Console.WriteLine("subtract");
string operation = Console.ReadLine();
Console.WriteLine();
Console.Clear();
if (operation == "Multiply")
{
double total1;
total1 = (value1 * value2);
Console.WriteLine(total1);
Console.ReadLine();
Console.Clear();
goto Valuechoice;
}
if (operation == "Divide")
{
double total2;
total2 = (value1 / value2);
Console.WriteLine(total2);
Console.ReadLine();
Console.Clear();
goto Valuechoice;
}
if (operation == "Add")
{
double total3;
total3 = (value1 + value2);
Console.WriteLine(total3);
Console.ReadLine();
Console.Clear();
goto Valuechoice;
}
if (operation == "Subtract")
{
double total4;
total4 = (value1 - value2);
Console.WriteLine(total4);
Console.ReadLine();
Console.Clear();
goto Valuechoice;
}
if (Console.ReadLine() == "Exit")
{
Environment.Exit(0);
}