public void ViewBooks(List <Book> books) { int sno = 1; Console.BackgroundColor = ConsoleColor.White; Console.ForegroundColor = ConsoleColor.DarkBlue; Console.WriteLine(" Id\tPrice\t\tName\t\t\t\t\t "); Console.WriteLine("-----------------------------------------------------------------"); Console.BackgroundColor = ConsoleColor.Black; Console.ForegroundColor = ConsoleColor.White; foreach (Book bookItem in books) { if (Convert.ToInt32(bookItem.GetPrice()) == 0) { Console.WriteLine(" " + sno + "\t" + "Free" + "\t\t" + bookItem.GetName()); } else { Console.WriteLine(" " + sno + "\t" + bookItem.GetPrice() + "\t\t" + bookItem.GetName()); } Console.WriteLine("-----------------------------------------------------------------"); sno++; } while (true) { Console.Write("Enter Id to View Book or "); Console.BackgroundColor = ConsoleColor.DarkBlue; Console.WriteLine("'Press 0 to go back on main menu'"); Console.ResetColor(); try { int id = Convert.ToInt32(Console.ReadLine()); if (id == 0) { Console.Clear(); ShowMenu(); SelectOption(); break; } else { Console.BackgroundColor = ConsoleColor.White; Console.ForegroundColor = ConsoleColor.DarkBlue; Console.WriteLine("\t\t\tBook Information\t\t\t "); Console.WriteLine("-----------------------------------------------------------------"); Console.ResetColor(); int bookId = --id; Book _book = books[bookId]; Console.WriteLine(_book.ToString()); Console.BackgroundColor = ConsoleColor.DarkYellow; Console.ForegroundColor = ConsoleColor.White; Console.WriteLine("\n Press 1 to add book to cart or 2 to view author(s) details"); Console.ResetColor(); int opt = Convert.ToInt32(Console.ReadLine()); if (opt == 1) { try { Console.Write("Enter Quantity : "); int qty = Convert.ToInt32(Console.ReadLine()); if (qty <= 0) { throw new Exception(); } AddItem(_book, qty); Console.WriteLine("\nYou have (" + user.GetShoppingCartBooks().Length + ") Items in your cart.\n"); } catch (Exception) { Console.WriteLine("Invalid qty"); } } else { ViewAuthors(_book.GetAuthors()); } } } catch (Exception) { Console.WriteLine("Invalid Input...Try again!!"); } } }