Write a program that declares a structure to store BookID, price and pages of a book. It defines two structure variables and inputs values. It displays the record of most costly book.
#include<iostream>
using namespace std;
struct book {
int BookID;
float price;
int pages;
};
int main() {
book b1, b2;
b1.BookID = 10;
b1.pages= 100;
b1.price = 10.50;
b2.BookID = 20;
b2.pages= 200;
b2.price = 20.87;
cout<<"1. "<<"ID " <<b1.BookID<<"; pages "<<b1.pages<<"; price "<<b1.price<<endl;
cout<<"2. "<<"ID " <<b2.BookID<<"; pages "<<b2.pages<<"; price "<<b2.price<<endl<<endl;
cout<<"The record of most costly book:"<<endl;
if(b1.price>b2.price)
cout<<"ID " <<b1.BookID<<"; pages "<<b1.pages<<"; price "<<b1.price;
else
cout<<"ID " <<b2.BookID<<"; pages "<<b2.pages<<"; price "<<b2.price;
cout<<endl;
}
Comments
Leave a comment