Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace whileExr_02_oldBooks
- {
- class Program
- {
- static void Main(string[] args)
- {
- // name of the book and number of books in the library
- string bookName = Console.ReadLine().ToLower();
- int allBooks = int.Parse(Console.ReadLine());
- string foundit = string.Empty;
- int searches = 0;
- // main loop for searching the book
- while (foundit != bookName)
- {
- foundit = Console.ReadLine().ToLower();
- searches++;
- if (searches == allBooks)
- {
- break;
- }
- }
- // output the result
- if (foundit == bookName)
- {
- Console.WriteLine($"You checked {searches -1} books and found it.");
- }
- else
- {
- Console.WriteLine("The book you search is not here!");
- Console.WriteLine($"You checked {searches} books.");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement