📜  c# 计算器 - C# 代码示例

📅  最后修改于: 2022-03-11 14:49:18.010000             🧑  作者: Mango

代码示例1
//A simple calculator guide for total c# begginers




//prompts and gathering data
                Console.Write("Enter a number: ");
                int N1 = Convert.ToInt32(Console.ReadLine());

                Console.Write("Enter an operator: ");
                string op = Console.ReadLine();

                Console.Write("Enter a number: ");
                int N2 = Convert.ToInt32(Console.ReadLine());

                //if statements
                if (op == "+")
                {
                    Console.WriteLine(N1 + N2);
                }else if (op == "-")
                {
                    Console.WriteLine(N1 - N2);
                }else if (op == "*")
                {
                    Console.WriteLine(N1 * N2);
                }else if (op == "/")
                {
                    Console.WriteLine(N1 / N2);
                }
                else
                {
                    //if not stated operator, say "error"
                    Console.WriteLine("Error");
                }
            }
            catch
            {
                //if other problem spotted, say "error
                Console.Write("Error");
            }