Help with code

  • Thread starter Thread starter Extra Account
  • Start date Start date
E

Extra Account

Guest
Hello,

I was looking into methods and I was wondering if there was a way to do this using methods and how I would go about doing it.

Thanks in advance.

Code

using System;

namespace Program_2
{
class Program
{
static void Main(string[] args)
{
double x1, y1, x2, y2, x3, y3, x4, y4, x5, y5, z, d1, d2, d3, d4, d5, xr, yr;
Console.WriteLine("Enter the number of suppliers:");
z = Convert.ToDouble(Console.ReadLine());
Console.WriteLine("Enter the X-Coordinate for supplier 1:");
x1 = Convert.ToDouble(Console.ReadLine());
Console.WriteLine("Enter the y-Coordinate for supplier 1:");
y1 = Convert.ToDouble(Console.ReadLine());
Console.WriteLine("Enter the X-Coordinate for supplier 2:");
x2 = Convert.ToDouble(Console.ReadLine());
Console.WriteLine("Enter the y-Coordinate for supplier 2:");
y2 = Convert.ToDouble(Console.ReadLine());
Console.WriteLine("Enter the X-Coordinate for supplier 3:");
x3 = Convert.ToDouble(Console.ReadLine());
Console.WriteLine("Enter the y-Coordinate for supplier 3:");
y3 = Convert.ToDouble(Console.ReadLine());
Console.WriteLine("Enter the X-Coordinate for supplier 4:");
x4 = Convert.ToDouble(Console.ReadLine());
Console.WriteLine("Enter the y-Coordinate for supplier 4:");
y4 = Convert.ToDouble(Console.ReadLine());
Console.WriteLine("Enter the X-Coordinate for supplier 5:");
x5 = Convert.ToDouble(Console.ReadLine());
Console.WriteLine("Enter the y-Coordinate for supplier 5:");
y5 = Convert.ToDouble(Console.ReadLine());

xr = (x1 + x2 + x3 + x4 + x5) / z;
yr = (y1 + y2 + y3 + y4 + y5) / z;
d1 = Math.Sqrt(((x1 - xr) * (x1 - xr)) + ((y1 - yr) * (y1 - yr)));
d2 = Math.Sqrt(((x2 - xr) * (x2 - xr)) + ((y2 - yr) * (y2 - yr)));
d3 = Math.Sqrt(((x3 - xr) * (x3 - xr)) + ((y3 - yr) * (y3 - yr)));
d4 = Math.Sqrt(((x4 - xr) * (x4 - xr)) + ((y4 - yr) * (y4 - yr)));
d5 = Math.Sqrt(((x5 - xr) * (x5 - xr)) + ((y5 - yr) * (y5 - yr)));

Console.WriteLine("The retail location should be located at the coordinates:" + (xr, yr));
Console.WriteLine("The distance from supplier 1 is:" + d1);
Console.WriteLine("The distance from supplier 2 is:" + d2);
Console.WriteLine("The distance from supplier 3 is:" + d3);
Console.WriteLine("The distance from supplier 4 is:" + d4);
Console.WriteLine("The distance from supplier 5 is:" + d5);
Console.ReadLine();
}
}
}

Continue reading...
 
Back
Top