Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- int main (void)
- {
- int digit1, digit2, i, j;
- int price[300] = {0}, paid_amt;
- int order_item[300] = {0}, order_qty[300] = {0}, order_price;
- int dollars[300] = {0}, cents[300] = {0};
- int amt_dollars[300] = {0}, amt_cents[300]= {0};
- int ttl_price = 0, count = 0;
- char dot;
- for(i = 0; i < ((sizeof(price))*2+1); i++)
- {
- scanf("%d%c%d", &digit1, &dot, &digit2); /* Scan input */
- if (dot == '.')
- {
- if(count==0)
- {
- dollars[i] = digit1;
- cents[i] = digit2;
- price[i]= (digit1*100) + digit2; /* Making price to cents */
- }
- else
- {
- paid_amt = (digit1*100) + digit2; /* Making paid to cents */
- break;
- }
- }
- else if (dot != '.')
- {
- order_item[i] = digit1; /* Seperate numbers between space */
- order_qty[i] = digit2;
- count = 1;
- }
- }
- if (paid_amt > 99999) /* Not more than $999 */
- {
- printf("The total amount paid by the user shall not exceed $999.99.\n");
- return 0;
- }
- for (j = 0; j < i; j++)
- {
- ttl_price += (price[order_item[j]] * order_qty[j]); /* Calculate total price */
- order_price = (price[order_item[j]] * order_qty[j]);
- amt_dollars[j] = order_price / 100;
- amt_cents[j] = order_price % 100;
- }
- printf("Description Unit Price Qty Amount\n");
- for (j = 0; j < i; j++)
- {
- 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]);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement