Files
2023-02-24 03:55:27 +00:00

43 lines
1.8 KiB
C

/*
Nicholas Pease
HW5D - Candies and POS
*/
#include <stdio.h>
#define PRICE_OF_CHOCOLATE 15.50
#define PRICE_OF_TOFFEE 6.90
int main() {
//being input section
// all variables below are used for input
char name[20];int chocolateBags,toffeeBags;
// get name and leave newline as it is helpful later
printf("Enter customer name: ");
fgets(name,20,stdin);
printf("Enter number of chocolate bags: ");
scanf("%d",&chocolateBags);
printf("Enter number of toffee bags: ");
scanf("%d",&toffeeBags);
// end input section
// calculate discount percentages for all items
// these values are multiplied, so its 1 - the decimal percentage off version
double chocolateDiscount = chocolateBags > 5? 0.9: 1;
double toffeeDiscount = toffeeBags > 2? .95: 1;
// totals
double chocolateDiscountTotal = PRICE_OF_CHOCOLATE*chocolateBags*chocolateDiscount;
double toffeeDiscountTotal = PRICE_OF_TOFFEE*toffeeBags*toffeeDiscount;
// start output section
printf("\n\tHello %s",name);
printf("Chocolates \t x%d \t $ %.2lf\n",chocolateBags,PRICE_OF_CHOCOLATE*chocolateBags);
printf("\tafter discount\t $ %.2lf\n\n",PRICE_OF_CHOCOLATE*chocolateBags*chocolateDiscount);
printf("Toffees \t x%d \t $ %.2lf\n",toffeeBags,PRICE_OF_TOFFEE*toffeeBags);
printf("\tafter discount\t $ %.2lf\n",PRICE_OF_TOFFEE*toffeeBags*toffeeDiscount);
double totalDiscount = (chocolateDiscountTotal + toffeeDiscountTotal) > 100? 0.9: 1;
double grandTotal = (chocolateDiscountTotal + toffeeDiscountTotal) * totalDiscount;
printf("\nTotal after discount\t $ %.2lf\n",chocolateDiscountTotal + toffeeDiscountTotal);
printf("after 10%% discount\t $ %.2lf\n",grandTotal);
printf("\n\tYou Owe\t\t $ %.2lf\n\tThank you!\n",grandTotal);
return 0;
}