期望的和类型或命名空间定义或期望的文件结尾

时间:2015-10-18 10:59:42

标签: c# console

public class CalculatorUI
{

        Calculator obj= new Calculator();

        public void Menu()
        {
            string choice;
            double value;
            double val1;
            double val2;

            System.Console.WriteLine("1: Addition");
            System.Console.WriteLine("2: Subtraction");
            System.Console.WriteLine("3: Multiplication");
            System.Console.WriteLine("4: Division");
            System.Console.WriteLine("5: Mod");
            System.Console.WriteLine("6: Square root");
            System.Console.WriteLine("0: Exit");

            System.Console.WriteLine("Select choice from menu: ");
            choice=System.Console.ReadLine();

            if(choice == 1)
            {
                System.Console.WriteLine("Enter Values: ");
                val1 = System.Console.ReadLine();
                val2 = System.Console.ReadLine();
                value =obj.Addition(val1 , val2);
            }
            else if(choice == 2)
            {
                System.Console.WriteLine("Enter Values: ");
                val1 = System.Console.ReadLine();
                val2 = System.Console.ReadLine();
                value =obj.Subtraction(val1 , val2);
            }
            else if(choice == 3)
            {
                System.Console.WriteLine("Enter Values: ");
                val1 = System.Console.ReadLine();
                val2 = System.Console.ReadLine();
                value =obj.Multiplication(val1 , val2);
            }
            else if(choice == 4)
            {
                System.Console.WriteLine("Enter Values: ");
                val1 = System.Console.ReadLine();
                val2 = System.Console.ReadLine();
                value =obj.Division(val1 , val2);
            }
            else if(choice == 5)
            {
                System.Console.WriteLine("Enter Values: ");
                val1 = System.Console.ReadLine();
                val2 = System.Console.ReadLine();
                value =obj.Mod(val1 , val2);
            }
            else if(choice == 6)
            {
                System.Console.WriteLine("Enter Value for squareroot: ");
                val1 = System.Console.ReadLine();
                value =obj.SquareRoot(val1);
            }
            else
            { 
                System.Console.WriteLine("Invalid Choice");
            }
        }

 public static void Main()
    { Menu();
    }
}

我在记事本上工作。所有括号都是完整的我不知道错误。它甚至没有编译。我已经制作了另一个名为calculator的类的对象,它被正确编译 编辑完成!
我在记事本上工作。所有括号都是完整的我不知道错误。它甚至没有编译。我已经创建了另一个名为calculator的类的对象,它被正确编译。

1 个答案:

答案 0 :(得分:0)

Menu()方法在Main()方法中。

你应该创建Menu()作为Main()的单独方法,从Main()调用Menu()并将计算器对象传递给它。或者将Menu()合并到Main()。