# Customer Bill problem

• 03-27-2009
karipap
Customer Bill problem
the question -

Write a C program to create a customer’s bill for a company. The company ARAFAT sells only five different products. They are TV, VCR, Remote Controller, CD Player and Tape Recorder. The unit prices are \$400.00, \$220.00, \$35.20, \$300.00 and \$150.00, respectively. The program must read the quantity of each piece of equipment purchased from the keyboard as shown below. It then calculates the cost of each item, the subtotal, the tax amount and the total cost after deduct the sale tax. 8.25% sales tax is applied.

The input data which is the quantity of each item sold is to be input into the program as an integer. The program must prompt the user for each quantity in a user friendly way as shown below. The numbers in boldface show the user’s entries.

SAMPLE OUTPUT

How Many TVs Were Sold? 3
How Many VCRs Were Sold? 5
How Many Remote Controllers Were Sold? 1
How Many CDs Were Sold? 2
How Many Tape Recorders Were Sold? 4

QTY DESCRIPTION UNIT PRICE TOTAL PRICE
--- ----------- ---------- -----------
XX TV 400.00 \$ XXXX.XX
XX VCR 220.00 \$ XXXX.XX
XX REMOTE CTRLR 35.20 \$ XXXX.XX
XX CD PLAYER 300.00 \$ XXXX.XX
XX TAPE RECORDER 150.00 \$ XXXX.XX
-----------
SUBTOTAL \$ XXXX.XX
TAX \$ XXXX.XX
TOTAL \$ XXXX.XX

this is my code -

Code:

``` #include<stdio.h> #define tax 8.25 #define TV_price 400.00 #define VCR_price 220.00 #define Remote_Controller_price 35.20 #define CD_Player_price 300.00 #define Tape_Recorder 150.00 void main() {     int TV, VCR, Remote_Controller, CD_Player, Tape_Recorder;     float subtotal, total;         printf("How Many TVs Were Sold?: ");     scanf("&d" ,&TV);         printf("How Many VCRs Were Sold?: ");     scanf("&d" ,&VCR);         printf("How Many Remote Controllers Were Sold?: ");     scanf("&d" ,&Remote_Controller);         printf("How Many Cd Players Were Sold?: ");     scanf("&d" ,&CD_Player);         printf("How Many tape Recorders Were Sold?: ");     scanf("&d" ,&Tape_Recorder);         //total_price=quantity*total price             printf("QTY          DESCRIPTION            UNIT PRICE                    TOTAL PRICE ");     printf("===          ===========        ==========            =========== ");         printf("%d              TV                              400.00                            " , TV , total_price );     printf("%d              VCR                          220.00                            " , VCR ,total_price );     printf("%d        Remote Controller            35.20                            " , Remote_Controller , total_price );     printf("%d            CD PLayer                  300.00                            " , CD_Player,total_price );     printf("%d          Tape Recorder              150.00                            " , Tape_Recorder ,total_price );         printf("                                                            -----------  " );                printf("                                      SUBTOTAL              %.2f        " , subtotal);                                                printf("                                      TAX                  %.2f        " , tax);     printf("                                      TOTAL                %.2f        " , total);                                                    getch()     }```
My problem is
how can i define Quantity so that i can calculate total_price?. thank you!
• 03-27-2009
vart
does not TV variable contains quantity of tvs that are brought? what else do you need?
• 03-27-2009
karipap
I have to do like this total_price=TV_price*quantity ?

what if the stuff is VCR, Remote Controller, CD Player and Tape Recorder? do i have to repeat the same calculation all over again?
• 03-27-2009
vart
Quote:

Originally Posted by karipap
I have to do like this total_price=TV_price*quantity ?

what if the stuff is VCR, Remote Controller, CD Player and Tape Recorder? do i have to repeat the same calculation all over again?

Think what you'll need to do in real life. and emulate it with your program
• 03-27-2009
Quote:

Originally Posted by karipap
the question -

Write a C program to create a customer’s bill for a company. The company ARAFAT sells only five different products. They are TV, VCR, Remote Controller, CD Player and Tape Recorder. The unit prices are \$400.00, \$220.00, \$35.20, \$300.00 and \$150.00, respectively. The program must read the quantity of each piece of equipment purchased from the keyboard as shown below. It then calculates the cost of each item, the subtotal, the tax amount and the total cost after deduct the sale tax. 8.25% sales tax is applied.

The input data which is the quantity of each item sold is to be input into the program as an integer. The program must prompt the user for each quantity in a user friendly way as shown below. The numbers in boldface show the user’s entries.

SAMPLE OUTPUT

How Many TVs Were Sold? 3
How Many VCRs Were Sold? 5
How Many Remote Controllers Were Sold? 1
How Many CDs Were Sold? 2
How Many Tape Recorders Were Sold? 4

QTY DESCRIPTION UNIT PRICE TOTAL PRICE
--- ----------- ---------- -----------
XX TV 400.00 \$ XXXX.XX
XX VCR 220.00 \$ XXXX.XX
XX REMOTE CTRLR 35.20 \$ XXXX.XX
XX CD PLAYER 300.00 \$ XXXX.XX
XX TAPE RECORDER 150.00 \$ XXXX.XX
-----------
SUBTOTAL \$ XXXX.XX
TAX \$ XXXX.XX
TOTAL \$ XXXX.XX

this is my code -

Code:

``` #include<stdio.h> #define tax 8.25 #define TV_price 400.00 #define VCR_price 220.00 #define Remote_Controller_price 35.20 #define CD_Player_price 300.00 #define Tape_Recorder 150.00 void main() {     int TV, VCR, Remote_Controller, CD_Player, Tape_Recorder;     float subtotal, total;         printf("How Many TVs Were Sold?: ");     scanf("&d" ,&TV);         printf("How Many VCRs Were Sold?: ");     scanf("&d" ,&VCR);         printf("How Many Remote Controllers Were Sold?: ");     scanf("&d" ,&Remote_Controller);         printf("How Many Cd Players Were Sold?: ");     scanf("&d" ,&CD_Player);         printf("How Many tape Recorders Were Sold?: ");     scanf("&d" ,&Tape_Recorder);         //total_price=quantity*total price   /*you might want an ext(ended) unit cost. That would be the cost for any item * the cost of one unit. So if someone bought two vcr's, their unit price would be 220 still, but their extended price would be 2 * 220 = 440. If you don't need to track how much was earned from each item in the store, you may just put it all together under "sub total". Let's say that we want to track the sales in \$\$\$ for each item, so we use an extCD_Player, extTape Recorder, extVCR, etc. The total figures then would be: if(TV > 0)   extTV = TV * TV_price; if(VCR > 0)   extVCR = VCR * VCR_price; if(RemoteController > 0)   extRemoteController = RemoteController * RemoteController_price; //and same for CD player and Tape Recorder. subtotal = extTV + extVCR +extRemoteController +extCD_Player + extTape_Recorder total = sub_total * 1.0825 (the tax rate of 8.25)             printf("QTY          DESCRIPTION            UNIT PRICE                    TOTAL PRICE ");     printf("===          ===========        ==========            =========== ");         printf("%d              TV                              400.00                            " , TV , total_price );     printf("%d              VCR                          220.00                            " , VCR ,total_price );     printf("%d        Remote Controller            35.20                            " , Remote_Controller , total_price );     printf("%d            CD PLayer                  300.00                            " , CD_Player,total_price );     printf("%d          Tape Recorder              150.00                            " , Tape_Recorder ,total_price );         printf("                                                            -----------  " );                printf("                                      SUBTOTAL              %.2f        " , subtotal);                                                printf("                                      TAX                  %.2f        " , tax);     printf("                                      TOTAL                %.2f        " , total);                                                    getch()     }```
My problem is
how can i define Quantity so that i can calculate total_price?. thank you!

You can't deduct the sales tax. Governments don't work that way. :) Taxes are an additional cost., as shown above in blue.
• 04-05-2009
karipap
thank you everyone and adak. r
```#include<stdio.h> #define tax 1.0825 #define TV_price 400.00 #define VCR_price 220.00 #define Remote_Controller_price 35.20 #define CD_Player_price 300.00 #define Tape_Recorder_price 150.00 int main() {     int TV, VCR, Remote_Controller, CD_Player, Tape_Recorder;     float price, subtotal, total, extTV=0, extVCR=0, extRemote_Controller=0, extCD_Player=0, extTape_Recorder=0, tax_deduct;         printf("How Many TVs Were Sold?: ");     scanf("%d" ,&TV);         printf("How Many VCRs Were Sold?: ");     scanf("%d" ,&VCR);         printf("How Many Remote Controllers Were Sold?: ");     scanf("%d" ,&Remote_Controller);         printf("How Many Cd Players Were Sold?: ");     scanf("%d" ,&CD_Player);         printf("How Many Tape Recorders Were Sold?: ");     scanf("%d" , &Tape_Recorder);             extTV = TV * TV_price;     extVCR = VCR * VCR_price;     extRemote_Controller = Remote_Controller * Remote_Controller_price;     extCD_Player = CD_Player * CD_Player_price;     extTape_Recorder = Tape_Recorder * Tape_Recorder_price;               subtotal = extTV + extVCR +extRemote_Controller +extCD_Player + extTape_Recorder ;      tax_deduct= tax*subtotal;     total = subtotal + tax_deduct ;           printf("\nQTY          DESCRIPTION            UNIT PRICE                    TOTAL PRICE ");     printf("\n===          ===========            ==========            =========== ");         printf("\n%d              TV                  400.00                    %.2f      " , TV , extTV  );     printf("\n%d              VCR                  220.00                      %.2f    " , VCR , extVCR);     printf("\n%d        Remote Controller          35.20                      %.2f    " , Remote_Controller , extRemote_Controller);     printf("\n%d            CD PLayer              300.00                      %.2f    " , CD_Player , extCD_Player );     printf("\n%d          Tape Recorder            150.00                      %.2f  " , Tape_Recorder , extTape_Recorder  );         printf("\n                                                            -----------  " );                printf("\n                                      SUBTOTAL              %.2f        " , subtotal);                                                printf("\n                                      TAX                  %.2f        " , tax_deduct);     printf("\n                                      TOTAL                %.2f        " , total);                                                    getche();         }```