Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace Task4
- {
- 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;
- bool bookFound = false;
- // main loop for searching the book
- for (int i = 0; i < allBooks; i++)
- {
- string foundit = Console.ReadLine();
- if (bookName == foundit)
- {
- bookFound = true;
- break;
- }
- searches++;
- }
- // output the result
- if (bookFound)
- {
- Console.WriteLine($"You checked {searches} books and found it.");
- }
- else
- {
- Console.WriteLine("The book you search is not here!");
- Console.WriteLine($"You checked {searches} books.");
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment