OK I've been really humbled. I've spent at least 8 hours trying to solve this problem and I've gotten nowhere! I am getting really weird behavior and am not sure how to proceed. Here's the problem and the steps I've taken to remedy the "bug". This works perfectly well stand alone with line 18 commented out.
Problem: The Console.ReadLine(); within the homework project (I'll refer to this as HW) returns the cursor to the beginning of the line it is reading after input and Enter. Here's the test module.
1 public static void ReserveMedia() 2 { 3 string k = ""; 4 string _reserverFor; 5 int _ordinal; 6 while (k != "-1") 7 { 8 Console.Write("Please select a number: "); 9 k = Console.ReadLine(); 10 if (k == "-1") 11 break; 12 13 _ordinal = Convert.ToInt32(k); 14 15 Console.WriteLine("You have selected the number {0}\n", k); 16 Console.Write("Now, please enter the name of the person reserving the media: "); 17 _reserverFor = Console.ReadLine(); 18 _reserverFor = Console.ReadLine(); 19 Console.WriteLine("You have selected {0}", _reserverFor); 20 }
}
If I run this routine from a simple project it works as expected. Within the code I get the following behavior: a. when I step from line 9 the cursor goes to the beginning of the "Please press" line of the console and requires a second Enter press to go back to code. b. line 17 still keeps the variable _reserveFor = "". I added a second ReadLine() (line 18) c. The second ReadLine() (line 18) reads the screen correctly after another Enter d. On the second loop around, entering a value and clicking enter still returns a k = ""
I have no clue as to why I have to double enter in this module. I've simplified my code as much as I think possible and need a clue as to where to go from here to resolve this.
.NET Development21
|