Question: This is the code but I want to add the stream reader so the input is taken from a text file. HELP! using System; using
This is the code but I want to add the stream reader so the input is taken from a text file. HELP!
using System; using System.IO;
namespace Lazy_Fox { class Program { static void Main(string[] args) { Console.WriteLine("Enter the number of neighbours: "); int N = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("Enter the coordinates for all the neighbours: ");
int[] x = new int[N]; int[] y = new int[N];
for(int i=0; i double totalTreats = calculations(0, 0, x, y, N, 9999999); Console.WriteLine(); Console.WriteLine("The total number of treats that the fox gathers is: "+totalTreats); } static int calculations(int currentX, int currentY, int[] x, int[] y, int N, double lastDistance) { if (lastDistance == 0) { return 1; } double maxDistance = 0; double distance; int index = 0; for (int i = 0; i < N; i++) { distance = Math.Sqrt(((currentX - x[i]) * (currentX - x[i])) + ((currentY - y[i]) * (currentY - y[i]))); if (distance < lastDistance) { if (distance > maxDistance) { maxDistance = distance; index = i; } } } if(maxDistance != 0) { return (1 + calculations(x[index], y[index], x, y, N, maxDistance)); } else { return 1; } } } }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
