Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2016
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.56 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. int main (void)
  4. {
  5.   int digit1, digit2, i, j;
  6.   int price[300] = {0}, paid_amt;
  7.   int order_item[300] = {0}, order_qty[300] = {0}, order_price;
  8.   int dollars[300] = {0}, cents[300] = {0};
  9.   int amt_dollars[300] = {0}, amt_cents[300]= {0};
  10.   int ttl_price = 0, count = 0;
  11.   char dot;
  12.  
  13.   for(i = 0; i < ((sizeof(price))*2+1); i++)
  14.   {  
  15.     scanf("%d%c%d", &digit1, &dot, &digit2); /* Scan input */
  16.  
  17.   if (dot == '.')
  18.   {
  19.     if(count==0)
  20.     {
  21.       dollars[i] = digit1;
  22.       cents[i] = digit2;
  23.       price[i]= (digit1*100) + digit2; /* Making price to cents */
  24.     }
  25.     else
  26.     {
  27.      
  28.       paid_amt = (digit1*100) + digit2; /* Making paid to cents */
  29.       break;
  30.     }
  31.   }
  32.   else if (dot != '.')
  33.   {
  34.     order_item[i] = digit1; /* Seperate numbers between space */
  35.     order_qty[i] = digit2;
  36.     count = 1;
  37.   }
  38.   }
  39.  
  40.   if (paid_amt > 99999) /* Not more than $999 */
  41.   {
  42.     printf("The total amount paid by the user shall not exceed $999.99.\n");
  43.     return 0;
  44.   }
  45.  
  46.  
  47.   for (j = 0; j < i; j++)
  48.     {
  49.     ttl_price += (price[order_item[j]] * order_qty[j]); /* Calculate total price */
  50.     order_price = (price[order_item[j]] * order_qty[j]);
  51.     amt_dollars[j] = order_price / 100;
  52.     amt_cents[j] = order_price % 100;
  53.     }
  54.  
  55.   printf("Description    Unit Price    Qty    Amount\n");
  56.   for (j = 0; j < i; j++)
  57.   {
  58.     printf("Item %3d           %3d.%02d    %-3d    %3d.%02d\n", order_item[j], dollars[order_item[j]], cents[order_item[j]], order_qty[j], amt_dollars[j], amt_cents[j]);
  59.   }
  60.  
  61.   return 0;
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement