8. Program that inputs total pages of a book, number of pages a person reads in one day and number of days a person has read the book. It displays number of pages that have been read and number of pages remaining.
Chapter 4:
Input And Output
Programming Exercise
Problem # 8:
Write a program that inputs total pages of a book, number of pages a person reads in one day and number of days a person has read the book. It displays number of pages that have been read and number of pages remaining.
Solution:
#include<iostream>
#include<conio.h>
using namespace std;
int main()
{
int totalPages, pagesReadPerDay, noOfDays, pagesRead, pagesRemaining;
cout<<"Enter total pages of a book : ";
cin>>totalPages;
cout<<"Enter number of pages a person reads in one day : ";
cin>>pagesReadPerDay;
cout<<"Enter number of days a person has read the book : ";
cin>>noOfDays;
pagesRead = pagesReadPerDay * noOfDays;
cout<<"Total number of pages read by the person : "<<pagesRead<<endl;
pagesRemaining = totalPages - pagesRead;
cout<<"Total number of pages remaining : "<<pagesRemaining<<endl;
return 0;
}
#include<conio.h>
using namespace std;
int main()
{
int totalPages, pagesReadPerDay, noOfDays, pagesRead, pagesRemaining;
cout<<"Enter total pages of a book : ";
cin>>totalPages;
cout<<"Enter number of pages a person reads in one day : ";
cin>>pagesReadPerDay;
cout<<"Enter number of days a person has read the book : ";
cin>>noOfDays;
pagesRead = pagesReadPerDay * noOfDays;
cout<<"Total number of pages read by the person : "<<pagesRead<<endl;
pagesRemaining = totalPages - pagesRead;
cout<<"Total number of pages remaining : "<<pagesRemaining<<endl;
return 0;
}
Code Screenshot:
Output:
Let me know in the comment section if you have any question.
Previous Post:
7. Program that inputs a number from user and displays its square and cube.
Comments
Post a Comment