IvetValcheva

Old Books

Oct 9th, 2022
222
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.65 KB | None | 0 0
  1. using System;
  2.  
  3. namespace demo
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             //1. Четем заглавието на любимата книга
  10.             string favouriteBook = Console.ReadLine();
  11.  
  12.             int count = 0;
  13.             string input = Console.ReadLine();
  14.  
  15.             //2. Пуснем цикъл, който да се изпълнява дотогава, докато не прочетем заглавията на всички книги
  16.             //=> докато не получим от конзолата "No More Books"
  17.             while (input!= "No More Books")
  18.             {
  19.                 //   => Проверяваме дали това е любимата книга
  20.                 if(input==favouriteBook)
  21.                 {
  22.                     //=> спираме цикъла
  23.                     Console.WriteLine($"You checked {count} books and found it.");
  24.                     break;
  25.                 }
  26.  
  27.                 //   => ако не сме я откирли:
  28.                 //          => увеличаваме брояча на заглавия, които сме прочели с 1
  29.                 count++;
  30.  
  31.                 //   => Четем заглавие на книга
  32.                 input = Console.ReadLine();
  33.             }
  34.  
  35.             //3. Проверяваме дали ne сме открили книгата
  36.             if (input != favouriteBook)
  37.             {
  38.                 Console.WriteLine("The book you search is not here!");
  39.                 Console.WriteLine($"You checked {count} books.");
  40.             }
  41.  
  42.  
  43.         }
  44.     }
  45. }
  46.  
Add Comment
Please, Sign In to add comment