@ThePhoton gave a good answer that I upvoted, but let me add a little to it.
In general, you use "the" when there is only one of the thing that you can be referring to, when taken in context. Use "a" when there is more than one.
Like, "I ate at a house on Elm Street." There are many houses on Elm Street. I visited one of the many. But, "I visited the house that Bob lives in." Bob presumably lives in only one house, so there's only one house that I can be talking about.
Sometimes either "a" or "the" is grammatically possible, but which you use depends on the facts. Like, "I got lunch in a diner in Cooperton" or "I got lunch in the diner in Cooperton"? If there is only one diner in Cooperton, then it should be "the". If there are two or more, it should be "a".
Whether something is "a" or "the" can change as the narrative proceeds. Often something is introduced as "a" because it is one of many. But once you have mentioned it, now it is the only one in the current context, so it becomes "the". For example, "In the bookstore, I found a book about aardvarks. I bought the book and found it fascinating." When I first mention this book, it is "a", because there are many books in the bookstore, maybe even many books about aardvarks, and this is one of the many. But once I focus attention on this book, now it becomes "the book", that is, the one book that I am now talking about.