SHARE
TWEET

Untitled

a guest Jan 21st, 2020 59 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include<iostream>
  2.  
  3. using namespace std;
  4.  
  5. struct Book {
  6.     char title[200];
  7.     char author[200];
  8.  
  9.     double price = 0;
  10.  
  11.     char yearOfPublishing[5];
  12. };
  13.  
  14. int main() {
  15.     Book books[10];
  16.  
  17.     for (int i = 0; i < 10; i++)
  18.     {
  19.         Book inputBook;
  20.  
  21.         cout << "Book title: "; cin.getline(inputBook.title, 200);
  22.         cout << "Book author: "; cin.getline(inputBook.author, 200);
  23.  
  24.         while (true) {
  25.             cout << "Book price: "; cin >> inputBook.price;
  26.             if (cin.fail()) {
  27.                 cin.clear();
  28.                 cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
  29.                 continue;
  30.             }
  31.             break;
  32.         }
  33.  
  34.         cin.ignore();
  35.        
  36.         cout << "Year of publishing: "; cin.getline(inputBook.yearOfPublishing, 5);
  37.  
  38.         books[i] = inputBook;
  39.     }
  40.  
  41.     for (int i = 0; i < 10; i++)
  42.     {
  43.         cout << "Book index: " << i << "\r\n";
  44.         cout << "   Book title: " << books[i].title << "\r\n";
  45.         cout << "   Book author: " << books[i].author << "\r\n";
  46.         cout << "   Book price: " << books[i].price << "\r\n";
  47.         cout << "   Year of publishing: " << books[i].yearOfPublishing << "\r\n";
  48.  
  49.     }
  50. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top