I have this C# console application code here that reads text from a file. when a user inputs a value, it searches the file for lines that contain that value. In my case, the console will ask for a room number, the console will then search room.txt for the room number thats split with ','
class Program
{
static void Main(string[] args)
{
int counter = 0;
string line;
string roomNumber;
Console.WriteLine("Enter room number");
roomNumber = Console.ReadLine();
// Read the file and display it line by line.
System.IO.StreamReader file = new
System.IO.StreamReader("room.txt");
while ((line = file.ReadLine()) != null)
{
string[] words = line.Split(',');
if (roomNumber == words[1])
{
Console.WriteLine(line);
}
counter++;
}
file.Close();
// Suspend the screen.
Console.ReadLine();
}
}
}
How do i make it so that it will write "Invalid room number" when it cant find it in the text file, and then loop back to asking the room number.