Question: THIS IS THE CODE. What is not working that my stream reader is only running once and so if there are multiple inputs from a

THIS IS THE CODE. What is not working that my stream reader is only running once and so if there are multiple inputs from a text file, it's not working. So for example if there are multiple inputs like

u 4 l 199 d 199 r 1 l 1 q 0 IN a text file...It will only run u 4 and not the rest....HELP!!!! (PLEASE DO ADD SOME EXPLAINATION)

using System; using System.IO;

namespace Group1_Drill_Assignment { class Program { static void Main(string[] args) { bool[,] wellpoints = new bool[400, 200]; points(wellpoints); //Console.WriteLine("Enter the first letter of the direction you want to drill in (u,d,l,r) and a positive legnth by which you want to drill (Enter q to quit) "); //Console.WriteLine(); //Console.ForegroundColor = ConsoleColor.Red; //Console.WriteLine("NOTE: Make sure to put a space between the direction and the length "); //Console.ForegroundColor = ConsoleColor.White;

//stream reader string line; using (StreamReader reader = new StreamReader("file.txt")) { line = reader.ReadLine(); Console.WriteLine(line); }

int[] currentIndex = { 199, 4 }; int[] nextIndex = { currentIndex[0], currentIndex[1] }; string[] p = line.Split(); char direction = char.Parse(p[0]);

while (direction != 'q') { int value = Int32.Parse(p[1]); getIndex(direction, value, currentIndex); bool safe = approveValues(currentIndex, nextIndex, wellpoints); string message = (safe) ? "safe" : "DANGER";

Console.WriteLine("{0} {1} {2}", currentIndex[0] - 200, (currentIndex[1] + 1) * -1, message); nextIndex[0] = currentIndex[0]; nextIndex[1] = currentIndex[1]; if (!safe) break; p = Console.ReadLine().Split(); direction = char.Parse(p[0]);

} }

public static void points(bool[,] wellpoints) { wellpoints[200, 0] = true; wellpoints[200, 2] = true; wellpoints[200, 1] = true; wellpoints[201, 2] = true; wellpoints[202, 2] = true; wellpoints[203, 2] = true; wellpoints[205, 2] = true; wellpoints[206, 2] = true; wellpoints[207, 2] = true; wellpoints[203, 3] = true; wellpoints[205, 3] = true; wellpoints[203, 4] = true; wellpoints[204, 4] = true; wellpoints[205, 4] = true; wellpoints[207, 3] = true; wellpoints[207, 4] = true; wellpoints[207, 5] = true; wellpoints[207, 6] = true; wellpoints[206, 6] = true; wellpoints[205, 6] = true; wellpoints[204, 6] = true; wellpoints[203, 6] = true; wellpoints[202, 6] = true; wellpoints[201, 6] = true; wellpoints[200, 6] = true; wellpoints[199, 6] = true; wellpoints[199, 5] = true; wellpoints[199, 4] = true; }

public static void getIndex(char d, int value, int[] currentIndex) { if (d=='u') { currentIndex[1] = currentIndex[1] - value; } else if (d == 'l') { currentIndex[0] = currentIndex[0] - value; } else if (d == 'd') { currentIndex[1] = currentIndex[1] + value; } else if (d == 'r') { currentIndex[0] = currentIndex[0] + value; } }

public static bool approveValues(int[] currentIndex, int[] nextIndex, bool[,] wellpoints) { bool value = true; int count = 0; for(int i = nextIndex[0]; i<=currentIndex[0]; i++) { for(int j = nextIndex[1]; j 1) { value = false; } count += 1; } } return value;

} } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!