In this program, you'll learn to declare structure book having data member as book_name, bookid, book_price. Accept this data for 3 books and display it.
#include<iostream>
using namespace std;
struct book
{
char book_name[20];
int bookid;
int book_price;
} b[3];
int main()
{
int i;
for(i=0; i<3; i++)
{
cout<<"Enter details for book " << i+1;
cin>> b[i].book_name;
cin>> b[i].bookid;
cin>> b[i].book_price;
}
cout<<"\nDetails of books :\n";
for(i=0; i<3; i++)
{
cout<< b[i].book_name << " ";
cout<< b[i].bookid << " ";
cout<< b[i].book_price << "\n";
}
}
Enter details for book 1 PCI 101 300
Enter details for book 2 BCC 102 350
Enter details for book 3 WPD 103 250
Details of books :
PCI 101 300
BCC 102 350
WPD 103 250