Unexpected Symbols Error

Blackreach10

New member
Joined
Jan 10, 2021
Messages
2
Programming Experience
Beginner
Hi I am a complete beginner doing an intro to C# course. I keep getting 'Unexpected symbol' error for the code below, no matter what I put in. Can anyone advise? Many thanks!
C#:
  /// <summary>
    /// Programming Assignment 1
    /// </summary>
    class Program
    {
        // x and y coordinates for points
        static float point1X;
        static float point1Y;
        static float point2X;
        static float point2Y;

        /// <summary>
        /// Calculates angle and distance between two points
        /// </summary>
        /// <param name="args">command-line args</param>
        static void Main(string[] args)
        {
            // loop while there's more input
            string input = Console.ReadLine();
            while (input[0] != 'q')
            {
                // extract point coordinates from string
                GetInputValuesFromString(input);

                // Add your code between this comment
                // and the comment below. You can of
                // course add more space between the
                // comments as needed

                float X1=2, Y1=2, X2=1, Y2=1
        

                //calculate the delta x and delta y between the two points
                float deltaX = Math.Pow((X2 - X1) ;
                float deltaY = Math.Pow((Y2 - Y1) ,

                //pythagoras theorem for distance
                var = Math.Sqrt(deltaY + deltaX),

                //atan2 for angle
                float radians = Math.Atan2((Y2 - Y1), (X2 - X1));

                //radians into degrees
                var angle = radians * (180 / Math.PI);

                WriteLine(Dist = + distance);
                WriteLine(angle = + angle);
 
Last edited by a moderator:
Here's how to post code (I fixed your post)
insertcode.png


You have several lines that ends with "," and none (line 30) - statements must end with ";" (Statements - C# language specification)
 
Many thanks - I changed that. Any ideas regarding the following?

/shared/submission/Program.cs - error CS1525: Unexpected symbol `float' (it's line 34). I've tried var as well.
 
A good idea here would be to sort the Error List window by line number and look at the first error which should be line 30 (in your post):
1610276581939.png

Error description is simply "; expected", so that is easy.

Then next is line 34 as you say
float deltaX = Math.Pow((X2 - X1) ;
That is messed up. Math.Pow(Double, Double) Method (System)
  • there is an extra "("
  • only one argument is given (x1-x1)
  • arguments type must be double
Why did you declare them float in line 30 when you expect to work with doubles? Same goes for return type, use correct type or declare the variable "var" for type to be inferred.
 
Back
Top Bottom