Answer:
#include<cstdio>
#include<conio.h>
using namespace std;
float totalcost(int totalbooks);
main()
{
int totalbooks;
float cost;
printf("enter the number of books");
scanf("%d",&totalbooks);
cost = totalcost (totalbooks);
printf("Total Purchasing Cost =%f",cost);
getch();
}
float totalcost(int totalbooks)
{
float cost, costperbook;
if(totalbooks<=20)
{
costperbook = 23.45;
return cost=costperbook*totalbooks;
}
else
if(totalbooks>=20 && totalbooks<=100)
{
costperbook = 21.11;
return cost=costperbook*totalbooks;
}
else
costperbook = 18.75;
return cost=costperbook*totalbooks;
}
Step-by-step explanation:
In this program a function has been used to calculate the total cost of the book. There is different cost for different number of books. To accomplish the task, two variable taken as float data type to store the total cost because cost of each book is assigned in decimal value. Total cost is the multiplication of cost per book and total number of books. As there is different cost for different number of books, so I use conditional statements to meet the demand of the cost per book.