Advertisement
Dianov

While Loop - Exercise (01. Old Books)

Dec 29th, 2020
203
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.00 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace OldBooks
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             string searchedBook = Console.ReadLine();
  14.             string input = Console.ReadLine();
  15.             int checkedBooksCounter = 0;
  16.  
  17.             while (input != searchedBook)
  18.             {                
  19.                 if (input == "No More Books")
  20.                 {
  21.                     Console.WriteLine("The book you search is not here!");
  22.                     Console.WriteLine($"You checked {checkedBooksCounter} books.");
  23.                     break;
  24.                 }
  25.                 checkedBooksCounter += 1;
  26.                 input = Console.ReadLine();                
  27.             }
  28.  
  29.             if (input == searchedBook)
  30.             {
  31.                 Console.WriteLine($"You checked {checkedBooksCounter} books and found it.");
  32.             }
  33.         }
  34.     }  
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement