desislava_topuzakova

Untitled

Jan 31st, 2022
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.68 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7. string favouriteBook;
  8. int totalBooksCount;
  9. getline(cin, favouriteBook);
  10. cin >> totalBooksCount;
  11. cin.ignore();
  12.  
  13. int currentBookCount = 0;
  14. bool bookIsFound = false;
  15. while (currentBookCount < totalBooksCount) {
  16. string currentBookName;
  17. getline(cin, currentBookName);
  18.  
  19. if (currentBookName == favouriteBook) {
  20. bookIsFound = true;
  21. break;
  22. }
  23. currentBookCount++;
  24. }
  25.  
  26. if (bookIsFound) {
  27. cout << "You checked " << currentBookCount << " books and found it.";
  28. }
  29. else {
  30. cout << "The book you search is not here!" << endl << "You checked " << currentBookCount << " books.";
  31. }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment