Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- using namespace std;
- struct Book {
- char title[200];
- char author[200];
- double price = 0;
- char yearOfPublishing[5];
- };
- int main() {
- Book books[10];
- for (int i = 0; i < 10; i++)
- {
- Book inputBook;
- cout << "Book title: "; cin.getline(inputBook.title, 200);
- cout << "Book author: "; cin.getline(inputBook.author, 200);
- while (true) {
- cout << "Book price: "; cin >> inputBook.price;
- if (cin.fail()) {
- cin.clear();
- cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
- continue;
- }
- break;
- }
- cin.ignore();
- cout << "Year of publishing: "; cin.getline(inputBook.yearOfPublishing, 5);
- books[i] = inputBook;
- }
- for (int i = 0; i < 10; i++)
- {
- cout << "Book index: " << i << "\r\n";
- cout << " Book title: " << books[i].title << "\r\n";
- cout << " Book author: " << books[i].author << "\r\n";
- cout << " Book price: " << books[i].price << "\r\n";
- cout << " Year of publishing: " << books[i].yearOfPublishing << "\r\n";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement