Advertisement
pdaogu

Ex5.1

Oct 9th, 2018
28
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.98 KB | None | 0 0
  1. #include <stdio.h>
  2. #define IPOD 148
  3. #define IPAD 288
  4. #define TOTAL 1020
  5.  
  6. int main () {
  7.   int ipod, ipad;
  8.   float total, discount;
  9.   printf("%*s%s%*s\n", 10, "", "Welcome to Topcare supermarket", 10, "");
  10.   printf("Please enter the numbers of products below that you would buy:\n");
  11.   printf("- Ipod: ");
  12.   scanf("%d", &ipod);
  13.   printf("- Ipad: ");
  14.   scanf("%d", &ipad);
  15.   printf("\nTOPCARE SUPERMARKET - BILL\n");
  16.   printf("---------------------------\n");
  17.   printf("%-*s%-*s%-*s\n", 5, "Qty", 15, "Product", 7, "Total");
  18.   printf("---------------------------\n");
  19.   printf("%-*d%-*s$%-*d\n", 5, ipod, 15, "Ipod", 6, ipod*IPOD);
  20.   printf("%-*d%-*s$%-*d\n\n", 5, ipad, 15, "Ipad", 6, ipad*IPAD);
  21.   total = ipod*IPOD + ipad*IPAD;
  22.   printf("Net: $%.2f\n\n", total);
  23.   printf("Your discount is %.0f%%\n", (discount = 10 * ((total > TOTAL) || ((ipod >= 3) && (ipad > 2)))));
  24.   printf("You pay $%.2f (-$%.2f) = $%.2f\n", total, total*discount/100, total*(1+discount/100));
  25.   return 0;
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement