Advertisement
Guest User

Untitled

a guest
Jan 2nd, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.03 KB | None | 0 0
  1. using System;
  2.  
  3. namespace ProgrammingAssignment1
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             // welcome message
  10.             Console.WriteLine("Welcome. This program will calculate the distance between two points" +
  11.                 " and the angle between those two points.");
  12.  
  13.             // declare variables
  14.             float point1x;
  15.             float point1y;
  16.             float point2x;
  17.             float point2y;
  18.  
  19.             // get values from user
  20.             Console.Write("First X Value: ");
  21.             point1x = float.Parse(Console.ReadLine());
  22.             Console.Write("First Y Value: ");
  23.             point1y = float.Parse(Console.ReadLine());
  24.             Console.Write("Second X Value: ");
  25.             point2x = float.Parse(Console.ReadLine());
  26.             Console.Write("Second Y Value: ");
  27.             point2y = float.Parse(Console.ReadLine());
  28.  
  29.             // calculate delta x
  30.             float deltax;
  31.             float deltay;
  32.             deltax = point2x - point1x;
  33.             deltay = point2y - point1y;
  34.  
  35.             // display delta
  36.             Console.WriteLine("Delta X: " + deltax);
  37.             Console.WriteLine("Delta Y: " + deltay);
  38.  
  39.             // calculate distance between points
  40.             double deltax2;
  41.             double deltay2;
  42.             double distance;
  43.             double distsqrt;
  44.             deltax2 = Math.Pow(deltax, deltax);
  45.             deltay2 = Math.Pow(deltay, deltay);
  46.             distsqrt = (deltax2 + deltay2);
  47.             distance = Math.Sqrt(distsqrt);
  48.  
  49.             // display distance
  50.             Console.WriteLine("Dx^2: " + deltax2);
  51.             Console.WriteLine("Dy^2: " + deltay2);
  52.             Console.WriteLine("DistSqrt: " + distsqrt);
  53.             Console.WriteLine("Distance: " + (float)distance);
  54.  
  55.             // calculate angle
  56.             double angle;
  57.             angle = Math.Atan2(point1y, point1x);
  58.  
  59.             // display angle
  60.             Console.WriteLine("Angle: " + angle);
  61.  
  62.  
  63.         }
  64.     }
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement