BXL
BXL

Reputation: 51

Why am I getting the error "Expected class, delegate, enum, interface or struct"

Can anyone tell me why am I getting this error? This is my first post to this forum. The research I have done to fix the problem on my own says I may have an improper curly brace somewhere, but I cannot locate it. Any help is greatly appreciated.


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

Upvotes: 2

Views: 867

Answers (3)

Anirudha
Anirudha

Reputation: 32807

main method or a method doesnt contain class or other methods

a class contains a single main method(which is the entry point to your app) or/and multiple methods

Also your //call methods is invalid..you have to pass values or variables.

Upvotes: 0

Rohit Vats
Rohit Vats

Reputation: 81243

Last brace is extra mate .This one -

}//End Main()

Also why last Console.ReadLine(); is misplaced. Shouldn't it be in under any method scope?

EDIT

I don't know what your code suppose to do. It contains lot of errors and the intent of code is not clear too. This code is compiling though -

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

Upvotes: 4

Rahul Tripathi
Rahul Tripathi

Reputation: 172488

The extra last brace }//End Main()

Upvotes: 2

Related Questions