Click here to Skip to main content
15,897,891 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
Popular Book Store plans to install a system to calculate the book cost based on the table below. Develop  a c-program to assist Popular to calculate the total cost during checkout. Input are: number of book(s),  and cost of each book.  
Type of  
member
Book Cost 
Remark
Normal  
member
5% discount 
Limited to 5 books per day. 
(e.g. buy 6, 5 cheapest books get the discount, 1 no discount)
Gold  
member
15% discount 
Limited to 3 books per day 
(e.g. buy 4, 3 cheapest books get the discount, 1 no discount) 
Non 
member
Buy 5 free 1 (for  1 time only)
Cheapest book will be given as free 
(e.g. buy more than 6, only the cheapest will be considered free of  charge.


What I have tried:

C
#include<studio.h>
int main()
{
	int qty,dis;
	float rate,total;
	printf("enter rate and quantity\n");
	scanf("%f %d", &rate,%qty)
}
Posted
Updated 13-Dec-20 23:00pm
v2

We are more than willing to help those that are stuck: but that doesn't mean that we are here to do it all for you! We can't do all the work, you are either getting paid for this, or it's part of your grades and it wouldn't be at all fair for us to do it all for you.

So we need you to do the work, and we will help you when you get stuck. That doesn't mean we will give you a step by step solution you can hand in!
Start by explaining where you are at the moment, and what the next step in the process is. Then tell us what you have tried to get that next step working, and what happened when you did.

If you are having problems getting started at all, then this may help: How to Write Code to Solve a Problem, A Beginner's Guide[^]
 
Share this answer
 
Use a struct for storing the pricing relevant info, e.g.
C
struct PriceInfo
{
  int discount; // percentage of discount, e.g. 15 means '15% discount'
  int limitation; // the maximum number of dicountable books.
};


Then, for instance
C
struct PriceInfo norm_pinfo = { 5, 5 }; // price info for normal members
struct PriceInfo gold_pinfo = { 15, 3 }; // price info for gold members

Should help to compute the price for normal and gold members. That's just a starter, for instance, the price computation for non-members is a corner case and should be trated in a separate way.
 
Share this answer
 
You need to visit some Learn C tutorial.

tip: use arrays and structs with pointers and functions to organize your code.

Some possible code snippets:
C++
struct Book
{
  float standardPrice;
  float endPrice;
  char name[100]
};

// ask user for data and allocate memory
Book* createBook();
// print data on screen
void print(Book *book);

//calculates the discount
calculateEndPrice(Book *books, int count, bool goldMember) {
  if( goldMember ) {
  } else {
  }
}
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900