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: