Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace ProgrammingAssignment1
- {
- class Program
- {
- static void Main(string[] args)
- {
- // welcome message
- Console.WriteLine("Welcome. This program will calculate the distance between two points" +
- " and the angle between those two points.");
- // declare variables
- float point1x;
- float point1y;
- float point2x;
- float point2y;
- // get values from user
- Console.Write("First X Value: ");
- point1x = float.Parse(Console.ReadLine());
- Console.Write("First Y Value: ");
- point1y = float.Parse(Console.ReadLine());
- Console.Write("Second X Value: ");
- point2x = float.Parse(Console.ReadLine());
- Console.Write("Second Y Value: ");
- point2y = float.Parse(Console.ReadLine());
- // calculate delta x
- float deltax;
- float deltay;
- deltax = point2x - point1x;
- deltay = point2y - point1y;
- // display delta
- Console.WriteLine("Delta X: " + deltax);
- Console.WriteLine("Delta Y: " + deltay);
- // calculate distance between points
- double deltax2;
- double deltay2;
- double distance;
- double distsqrt;
- deltax2 = Math.Pow(deltax, deltax);
- deltay2 = Math.Pow(deltay, deltay);
- distsqrt = (deltax2 + deltay2);
- distance = Math.Sqrt(distsqrt);
- // display distance
- Console.WriteLine("Dx^2: " + deltax2);
- Console.WriteLine("Dy^2: " + deltay2);
- Console.WriteLine("DistSqrt: " + distsqrt);
- Console.WriteLine("Distance: " + (float)distance);
- // calculate angle
- double angle;
- angle = Math.Atan2(point1y, point1x);
- // display angle
- Console.WriteLine("Angle: " + angle);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement