Guest User

Library

a guest
Nov 3rd, 2018
728
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.26 KB | None | 0 0
  1. //Rextester.Program.Main is the entry point for your code. Don't change it.
  2. //Compiler version 4.0.30319.17929 for Microsoft (R) .NET Framework 4.5
  3.  
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9.  
  10. namespace whileExr_02_oldBooks
  11. {
  12.     class Program
  13.     {
  14.         static void Main(string[] args)
  15.         {
  16.             // name of the book and number of books in the library
  17.             string bookName = Console.ReadLine();
  18.             int allBooks = int.Parse(Console.ReadLine());
  19.          
  20.             int searches = 0;
  21.  
  22.             // main loop for searching the book
  23.             while (true)
  24.             {
  25.                 string foundit = Console.ReadLine();
  26.                 searches++;
  27.              
  28.              if (foundit == bookName)
  29.             {
  30.                 Console.WriteLine($"You checked {searches -1} books and found it.");
  31.            break;
  32.             }
  33.             else if(searches == allBooks)
  34.             {
  35.                 Console.WriteLine("The book you search is not here!");
  36.                 Console.WriteLine($"You checked {searches} books.");
  37.             break;          
  38.              }
  39.             }
  40.  
  41.             // output the result
  42.            
  43.         }
  44.     }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment