public void AddBook() { Console.WriteLine("ADD A BOOK!"); Console.WriteLine("Author name?"); string author = Console.ReadLine(); Console.WriteLine("Title?"); string title = Console.ReadLine(); double price = -1; while (price < 0) { Console.WriteLine("Price?"); if (!Double.TryParse(Console.ReadLine(), out price)) { Console.WriteLine("I'm sorry, but that's not a number!"); price = -1; } else if (price < 0) { Console.WriteLine("I'm sorry, but the number must be zero, or greater!!"); } } ErrorCode ec = theList.Add(author, title, price); errors(ec); // STUDENTS: YOUR ERROR-CHECKING CODE SHOULD GO HERE! }
public void AddBook() { Console.WriteLine("ADD A BOOK!"); Console.WriteLine("Author name?"); string author = Console.ReadLine(); Console.WriteLine("Title?"); string title = Console.ReadLine(); double price = -1; while (price < 0) { Console.WriteLine("Price?"); if (!Double.TryParse(Console.ReadLine(), out price)) { Console.WriteLine("I'm sorry, but that's not a number!"); price = -1; } else if (price < 0) { Console.WriteLine("I'm sorry, but the number must be zero, or greater!!"); } } //if ec is Duplicate Book, print the message to the user //if ec is OK, print the message to the user ErrorCode ec = theList.Add(author, title, price); if (ec == ErrorCode.DuplicateBook) { Console.WriteLine("Book is a duplicate!"); } else if (ec == ErrorCode.OK) { Console.WriteLine("Book was added!"); } }
public void AddBook() { Console.WriteLine(); //Spacing/aesthetics Console.WriteLine("ADD A BOOK!"); Console.WriteLine("Author name?"); string author = Console.ReadLine(); Console.WriteLine("Title?"); string title = Console.ReadLine(); double price = -1; while (price < 0) { Console.WriteLine("Price?"); if (!Double.TryParse(Console.ReadLine(), out price)) { Console.WriteLine("Sorry, your entry is not a valid price!"); price = -1; } else if (price < 0) { Console.WriteLine("Sorry, you must enter a number greater than or equal to zero!"); } } ErrorCode ec = theList.Add(author, title, price); if (ec == ErrorCode.DuplicateBook) { Console.WriteLine("This book is already in the library!"); } else { Console.WriteLine("This book was successfully added to the library."); } }
public void AddBook() { Console.WriteLine("ADD A BOOK!"); Console.WriteLine("Author name?"); string author = Console.ReadLine(); Console.WriteLine("Title?"); string title = Console.ReadLine(); double price = -1; while (price < 0) { Console.WriteLine("Price?"); if (!Double.TryParse(Console.ReadLine(), out price)) { Console.WriteLine("I'm sorry, but that's not a number!"); price = -1; } else if (price < 0) { Console.WriteLine("I'm sorry, but the number must be zero, or greater!!"); } } ErrorCode ec = theList.Add(author, title, price); if (ec == ErrorCode.DuplicateBook) { Console.WriteLine("Duplicate book found. Entry failed!"); } if (ec == ErrorCode.OK) { Console.WriteLine("Book was successfully entered."); } }
public void AddBook() { Console.WriteLine("ADD A BOOK!"); Console.WriteLine("Author name?"); string author = Console.ReadLine(); Console.WriteLine("Title?"); string title = Console.ReadLine(); double price = -1; while (price < 0) { Console.WriteLine("Price?"); if (!Double.TryParse(Console.ReadLine(), out price)) { Console.WriteLine("I'm sorry, but that's not a number!"); price = -1; } else if (price < 0) { Console.WriteLine("I'm sorry, but the number must be zero, or greater!!"); } } ErrorCode ec = theList.Add(author, title, price); if (ec == ErrorCode.OK) { Console.WriteLine("successfully added a book"); } else { Console.WriteLine("failed to add a book");//make thses more fancy } }