Thread: Customer Bill problem

  1. #1
    Registered User
    Join Date
    Mar 2009
    Posts
    16

    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!

  2. #2
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    does not TV variable contains quantity of tvs that are brought? what else do you need?
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  3. #3
    Registered User
    Join Date
    Mar 2009
    Posts
    16
    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?

  4. #4
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    Quote Originally Posted by karipap View Post
    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
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  5. #5
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Quote Originally Posted by karipap View Post
    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.

  6. #6
    Registered User
    Join Date
    Mar 2009
    Posts
    16
    thank you everyone and adak. r
    this is the final answer.

    Code:
    #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();
         
         }

  7. #7
    DESTINY BEN10's Avatar
    Join Date
    Jul 2008
    Location
    in front of my computer
    Posts
    804
    return 0; at the end of the program.this means proper termination.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. searching problem
    By DaMenge in forum C Programming
    Replies: 9
    Last Post: 09-12-2005, 01:04 AM
  2. Bin packing problem....
    By 81N4RY_DR460N in forum C++ Programming
    Replies: 0
    Last Post: 08-01-2005, 05:20 AM
  3. half ADT (nested struct) problem...
    By CyC|OpS in forum C Programming
    Replies: 1
    Last Post: 10-26-2002, 08:37 AM
  4. binary tree problem - help needed
    By sanju in forum C Programming
    Replies: 4
    Last Post: 10-16-2002, 05:18 AM
  5. Difficult programming problem
    By ccmac in forum C++ Programming
    Replies: 3
    Last Post: 02-25-2002, 04:58 PM