B: Console.WriteLine("请输入第一个数字"); int second; try { second = int.Parse(Console.ReadLine());//同上 } catch (Exception) { Console.WriteLine("请输入数字\n"); goto B; } C : Console.WriteLine("请输入运算符,+-*/\n"); string third; third = Console.ReadLine(); if (third == "+" || third == "-" || third == "*" || third == "/")//判断输入的运算符是否合法 { goto D; } else//如果不合法的话... { Console.WriteLine("请输入正确的运算符\n"); goto C; } D: Console.WriteLine("请输入第二个数字"); int fourth; try { fourth = int.Parse(Console.ReadLine());//同上 } catch (Exception) { Console.WriteLine("请输入数字\n"); goto D; } //判断输入的运算符 if(third == "+") { Add(second, fourth); } if (third == "-") { Minus(second, fourth); } if (third == "*") { Mul(second, fourth); } if (third == "/") { Div(second, fourth); }
} //运算 staticvoidAdd(int a , int b) { int c; c = a + b; Console.WriteLine("\n结果等于" + c); Console.ReadKey(); } staticvoidMinus(int a, int b) { int c; c = a - b; Console.WriteLine("\n结果等于" + c); Console.ReadKey(); } staticvoidMul(int a, int b) { int c; c = a * b; Console.WriteLine("\n结果等于" + c); Console.ReadKey(); } staticvoidDiv(int a, int b) { int c; c = a / b; Console.WriteLine("\n结果等于" + c); Console.ReadKey(); } } }