A customer needs a specific amount of paper. The charges on the paper are $0.10 for single sheets, $0.055 for amounts in multiples of 100 sheets, $0.04 in multiples of 500 sheets, and $0.03 in multiples of 1000 sheets Write a C Program to calculate the type and number of package(s) for the least amount of money the customer should buy, given the minimum amount of sheets the customer needs. For example, if the customer needs 380 sheets, the amount she would pay when buying in multiples of 100 would be $22.00. However, if the customer bought 500 sheets, the cost would be $20.00. It would be cost effective for the customer to buy a package of 500 sheets.
CODE:
#include<stdio.h>
main (){
int sheets;
int num1000;
int num500;
int num100;
int num;
float cost1000;
float cost500;
float cost100;
float cost;
float total;
//INPUT//
printf("Enter number of sheets of paper needed: ");
scanf("%d",&sheets);
num =sheets%100;
num100 =((sheets%500)/ 100);
if ((sheets%100)>=55){ num100 =num100 + 1;}
if ((sheets%100)>=55) { num = 0;}
num500 =((sheets%1000)/500);
if ((sheets%500)>=335) { num500 = num500+1;}
if ((sheets%500) >= 335) { num100 = 0;}
num1000 =sheets/1000;
if ((sheets%1000) >= 645){num1000 =num1000 + 1;}
if ((sheets%1000) >= 645) { num500 = 0;}
if ((sheets%1000) >= 645) { num100 = 0;}
if ((sheets%1000) >= 645) { num = 0;}
cost1000 = num1000*30;
cost500 = num500*20;
cost100 =num100*5.5;
cost=num*0.1;
total = cost + cost100 + cost500 + cost1000;
printf("Number of 1000 packages:%d\n",num1000);
printf("Number of 500 packages:%d\n",num500);
printf("Number of 100 packages:%d\n",num100);
printf("Number of singles:%d\n",num);
printf("Total cost: %d$",total);
return 0;
}
Program Output:
For more problems click here
No comments:
Post a Comment