Delta X and Delta Y between two points?

Status
Not open for further replies.

jacob_1988

Member
Joined
Mar 3, 2016
Messages
9
Programming Experience
Beginner
I have written some C# code that is suppose to show the ouput of 'Distance between points: 1.414 degrees' and 'Angle between points: -135.000'. But I keep getting the same output irregardless of the input i.e. if I enter any numbers at the prompt I still get: Distance between points: 1.414214 and Angle between points: 45.
    static void Main(string[] args)
    {
        
                                         //prompt for and get the x value
                                         Console.Write("Enter X value");
                       float point1X = float.Parse(Console.ReadLine());
                                         Console.WriteLine();

                       //prompt for and get the y value
                       Console.Write("Enter Y value");
                                         float point1Y = float.Parse(Console.ReadLine());
                                         Console.WriteLine();

                                         //calculate the delta x and delta y between the two points
                                        float deltaY = 2 - 1;
                                 float deltaX = 2 - 1;
        
                                 //atan2 for angle
                                        float angle = (float)Math.Atan2(deltaY, deltaX) * 180 / (float)Math.PI;

                                 //Pythagoras theorem
                                         float distance =(float)Math.Sqrt(deltaX * deltaX + deltaY * deltaY);

                                 //output distance between points
                                        Console.WriteLine("Distance between points {0} ", distance);

                                        //output angle between points
                                       Console.WriteLine("Angle between points {0} ", angle);
                               }
                      }
                }
 
Last edited:
Firstly, I have fixed the formatting of your code, at least to some degree. Please use appropriate formatting tags when posting code snippets so that the code is easy to read, most importantly by maintaining indenting.

Secondly, there is no such word as "irregardless". You can use "irrespective" or "regardless" but not a mongrel spawn of both.

As for the issue, have you debugged your code? If not, now is the time to do so. Place a breakpoint at the top of the code and step through it line by line. At each step, check the values of your variables to make sure that they are what you think they should be. As soon as you find one isn't, you've found where the issue is and you can concentrate on that further.

To be honest, your issue is glaringly obvious but we all overlook stupid mistakes at times because we see what we expect to see. That's why we debug. As soon as you do that, it should become glaringly obvious to you too.
 
Can you close my forum account, I've posted a few times on this forum and not once has any reply been of any value.
 
Can you close my forum account, I've posted a few times on this forum and not once has any reply been of any value.

I can't speak for your other threads but if you can't find any value here then that's down to you. Debugging is an essential skill for any developer. Without it you're just not doing software development. If you're not prepared to make the effort to do the basics and use a breakpoint then you're not doing software development and you're not doing anything to help yourself. The choice is yours. Spit the dummy because you weren't given a fish or put the fishing lesson to use to help yourself now and in the future.
 
Status
Not open for further replies.

Latest posts

Back
Top Bottom