anizko

01. Old Books

Apr 4th, 2019
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.02 KB | None | 0 0
  1. using System;
  2.  
  3. namespace While_Loop___Exercise
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.  
  10.             string NameBook = Console.ReadLine();
  11.             int CountBook = int.Parse(Console.ReadLine());
  12.             int Counter = 0;
  13.  
  14.             string SearchBook = Console.ReadLine();
  15.              
  16.  
  17.             while (NameBook!=SearchBook)
  18.             {
  19.  
  20.                 if (Counter < CountBook)
  21.                 {
  22.                     SearchBook = Console.ReadLine();
  23.                    
  24.                 }
  25.                 else if (Counter >= CountBook)
  26.                 {
  27.                     Console.WriteLine("The book you search is not here!");
  28.                     Console.WriteLine($"You checked {Counter} books.");
  29.                     break;
  30.                 }
  31.                 ++Counter;
  32.  
  33.             }
  34.             if (NameBook == SearchBook)
  35.             {
  36.                 Console.WriteLine($"You checked {Counter} books and found it.");
  37.             }
  38.  
  39.  
  40.         }
  41.     }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment