Not a member of Pastebin yet?
                        Sign Up,
                        it unlocks many cool features!                    
                - //Rextester.Program.Main is the entry point for your code. Don't change it.
- //Compiler version 4.0.30319.17929 for Microsoft (R) .NET Framework 4.5
- 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();
- int allBooks = int.Parse(Console.ReadLine());
- int searches = 0;
- // main loop for searching the book
- while (true)
- {
- string foundit = Console.ReadLine();
- searches++;
- if (foundit == bookName)
- {
- Console.WriteLine($"You checked {searches -1} books and found it.");
- break;
- }
- else if(searches == allBooks)
- {
- Console.WriteLine("The book you search is not here!");
- Console.WriteLine($"You checked {searches} books.");
- break;
- }
- }
- // output the result
- }
- }
- }
Advertisement
 
                    Add Comment                
                
                        Please, Sign In to add comment                    
                 
                    