quite new to C#. I have the following code that calculates the distance and angle between two points. However, it won't display the decimal points (needs to be to three decimal places. I thought that float data type could handle decimal numbers?
e.g. point 1 x = 2, point 1 y = 2, point 2 x = 1, point 2 y = 1.
Distance gets calculated as 1 and angle gets calculated as -1. Distance should be 1.414 & angle should be -135.000 degrees, so its like its rounded them up / down if that makes sense...
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AngleDistanceCalc
{
class Program
{
static void Main(string[] args)
{
// print welcome message
Console.WriteLine("Welcome. This application will calculate the distance between two points and display the angle.");
Console.WriteLine("Please enter point 1 X value:");
float point1X = float.Parse(Console.ReadLine());
Console.WriteLine("Please enter point 1 Y value:");
float point1Y = float.Parse(Console.ReadLine());
Console.WriteLine("Please enter point 2 X value:");
float point2X = float.Parse(Console.ReadLine());
Console.WriteLine("Please enter point 2 y value:");
float point2Y = float.Parse(Console.ReadLine());
float deltaX = point2X - point1X;
float deltaY = point2Y - point2X;
double distance = Math.Sqrt(deltaX * deltaX + deltaY * deltaY);
Console.WriteLine("The distance between the points is: {0}", distance);
Console.WriteLine("The angle between the points is: {0}", deltaX);
}
}
}