Calculate a discounted price
#include <stdio.h>
int main()
{
const int level1 = 30;
const int level2 = 50;
const double discount1 = 0.10;
const double discount2 = 0.15;
const double unit_price = 3.50;
int q1 = 0;
int q2 = 0;
int qty_over_level1 = 0;
int qty_over_level2 = 0;
printf("Quantity?: ");
scanf("%d", &q1);
q2 = q1;
qty_over_level2 = q1%level2;
q1 -= qty_over_level2;
qty_over_level1 = q1%level1;
q1 -= qty_over_level1;
printf("\nThe total price for %d is $%.2lf\n", q2,
unit_price*(q1+(1.0-discount1)*qty_over_level1+(1.0-discount2)*qty_over_level2));
}
Related examples in the same category