2

谁能告诉我为什么会出现这个错误?这是我在这个论坛上的第一篇文章。我为自己解决问题所做的研究表明,我可能在某处有一个不正确的花括号,但我找不到它。任何帮助是极大的赞赏。


using System;

    class Program
    {
    //declare constant
    const double ANGLES_FROM_RADIANS = 57.295779513082323;

    static void Main()
    {

        //declare vairiables
        double xc = 0.0;
        double yc = 0.0;
        double radius = 0.0;
        double theta = 0.0;

        //call methods
        double GetUserInput (ref double xc, ref double yc);
        double CalcCoords (double xc, double yc, ref double radius, ref double theta);
        double Output (double radius, double theta);
     }


    //method prologue

    static double GetUserInput (ref double xc, ref double yc)
    {
        xc = 0;
        yc = 0;
        while (xc = 0)
        {
     Console.WriteLine("Please enter a possitive, non-zero value for the  x-ccordinate   of a point.");
            xc = int.Parse(Console.ReadLine());
            if (xc <= 0)
            {
                Console.WriteLine("Error, x must be greater than zero.");
            }
        }
        Console.WriteLine("Please enter a possitive value for the y-coordinate of a point.");
        yc = int.Parse(Console.ReadLine());

        Return Console.WriteLine("Your Coordinates are ({0},{1})", xc, yc);
    }

    //method prologue
    static double CalcCoords (double xc, double yc, ref double radius, ref double theta)
    {
            {
            radius = Math.sqrt((xc * yc) + (xc * yc));
            return radius;
            }
            {
            theta = Math.Atan(yc / xc) * ANGLES_FROM_RADIANS;
            return theta;
        }
    }

    //method prologue
    static double Output (double radius, double theta)
    {
        Console.WriteLine("For your polar coordinates:");
        Console.WriteLine("Distance from the origin: {0:f}", radius);
        Console.WriteLine("The angle (in degrees) from the x-axis is: {0:f3}", theta);
    }   

        Console.ReadLine();

    }//End Main()
    }//End class Program
4

3 回答 3

4

最后一个大括号是额外的伴侣。这个 -

}//End Main()

还有为什么最后Console.ReadLine();misplaced. 它不应该在任何方法范围内吗?

编辑

我不知道你的代码应该做什么。它包含很多,errorsintent of code不清楚。这段代码正在编译 -

class Program
    {
        //declare constant
        const double ANGLES_FROM_RADIANS = 57.295779513082323;

        static void shdg()
        {
            //declare vairiables
            double xc = 0.0;
            double yc = 0.0;
            double radius = 0.0;
            double theta = 0.0;
        }

        //method prologue
        static void GetUserInput(ref double xc, ref double yc)
        {
            xc = 0;
            yc = 0;
            while (xc == 0)
            {
                Console.WriteLine("Please enter a possitive, non-zero value for the  x-ccordinate   of a point.");
                xc = int.Parse(Console.ReadLine());
                if (xc <= 0)
                {
                    Console.WriteLine("Error, x must be greater than zero.");
                }
            }
            Console.WriteLine("Please enter a possitive value for the y-coordinate of a point.");
            yc = int.Parse(Console.ReadLine());

            Console.WriteLine("Your Coordinates are ({0},{1})", xc, yc);
        }

        //method prologue
        static double CalcCoords(double xc, double yc, ref double radius, ref double theta)
        {
            {
                radius = Math.Sqrt((xc * yc) + (xc * yc));
                return radius;
            }
            {
                theta = Math.Atan(yc / xc) * ANGLES_FROM_RADIANS;
                return theta;
            }
        }

        //method prologue
        static void Output(double radius, double theta)
        {
            Console.WriteLine("For your polar coordinates:");
            Console.WriteLine("Distance from the origin: {0:f}", radius);
            Console.WriteLine("The angle (in degrees) from the x-axis is: {0:f3}", theta);
        }
    }//End class Program
于 2012-10-21T18:34:20.240 回答
2

额外的最后一个大括号}//End Main()

于 2012-10-21T18:35:16.920 回答
0

main methodmethod不包含class或其他方法

aclass包含单个main方法(这是您的应用程序的入口点)或/和多个methods

//call methods也是无效的..你必须传递值或变量。

于 2012-10-21T18:37:41.417 回答