- 3
C++program that declares a structure to store id,pages and price of a book.Display the least and costly book details
Write a c++ program that declares a structure to store id, pages and price of a book. It defines an array of structures to store the records of five books. It inputs the record of five books and display the record of most costly and least costly book.
6 ответов
+ 5
Arslanzafar Zafar , before we are going to help you, please present your attempt here. if you haven't done a try by yourself so far, please do so, and post it here.
please also provide a proper task description with sample of input and output.
thanks!
+ 1
Lothar #include<iostream>
using namespace std;
struct book
{
int BookID;
float price;
int pages;
};
int main()
{
book b[5];
float least=0,costly=0;
cout<<"Enter bookID:"<<endl;
for(int i=0;i<5;i++)
{
cin>>b[i].BookID;
}
for(int i=1;i<=5;i++)
{
cout<<"Enter the pages of "<<i<<" book:"<<endl;
cin>>b[i].pages;
cout<<"Enter the price of "<<i<<" book:"<<endl;
cin>>b[i].price;
}
cin.ignore();
for(int i=1;i<=5;i++)
{
if(b[i].price>b[i+1].price)
{
least=b[i+1].price;
}
else
least=b[i].price;
}
cin.ignore();
for(int i=1;i<=5;i++)
{
if(b[i].price<b[i+1].price)
{
costly=b[i+1].price;
}
else
costly=b[i].price;
}
cout<<"Least book is: "<<least<<endl;
cout<<"Costly book is :"<<costly;
}
0
Lothar its a logical error but i don't know which one