can someone check this code

This is a discussion on can someone check this code within the C Programming forums, part of the General Programming Boards category; code: Code: #include <stdio.h> #include <math.h> /**********************************************************************************************************/ Sales Tax /**********************************************************************************************************/ /* Developed by: Glenn Wiggins */ /* */ /**********************************************************************************************************/ /* ...

  1. #1
    Registered User
    Join Date
    Sep 2002
    Posts
    4

    can someone check this code

    code:

    Code:
    #include <stdio.h>
    #include <math.h>
    /**********************************************************************************************************/
    Sales Tax
    /**********************************************************************************************************/
    /*                                                                                 Developed by:  Glenn Wiggins                                                                              */
    /*                                                                                                                                                                                                                 */
    /**********************************************************************************************************/
    /*	This program will compute a 6% sale tax on a purchase.  The program user is to input the total amount of the                   */
    /*     purchase.  The program is to return the original amount of the purchase, the tax, and the total of the two.                                    */
    /**********************************************************************************************************/
    /*                                                                                      Variables used:                                                                                                  */
    /*------------------------------------------------------------------------------------------------------------------------------------------------------------*/
    /*                                                            Purchase_amount = Total amount of purchase                                                                          */
    /*                                                                         Sale_tax = Total amount of sale tax                                                                              */
    /*                                                            Total_sum = Total amount of purchase and total amount of sale tax added together                */                                
    /**********************************************************************************************************/
    /*                                                                                      Constants used:                                                                                                 */
    /*------------------------------------------------------------------------------------------------------------------------------------------------------------*/
    /*                                                                          I = .06   (Sale tax percentage)                                                                                       */ 
    /**********************************************************************************************************/
    
    int main(void )
    
    {   
          /* Declarations block */
    
          float  Purchase_amount;		/* Amount purchased.		*/
          float  Sale_tax;			/*Amount of sales tax.	*/
          float  Total_sum;			/*Total amount owed.		*/
          float I = .06;			/* Precent sale tax.		*/
    
          /*  Explain the program to the user.  */
    
          puts (“”) ;
          puts (“This program will compute a 6% sales tax on a purchase.”) ;
          puts (“It will return the original amount of the purchase, the tax, “) ;
          puts (“and the total of the two.”) ;
          puts (“”) ;
    
          puts (“You on ly need to enter the total amount purchased.”) ;
    
          /* Get total amount purchase from user.  */
    
          puts (“”) ;
          printf (“Enter the total amount purchase  =>  “) ;
          scanf ( “%f”,  &   purchase_amount) ;
    
          /*  Do computations.  */
    
          Sale_tax = I * Purchase_amount ;

    Code tags added by kermi3

  2. #2
    Registered User
    Join Date
    Sep 2002
    Posts
    4

    i am confuse

    i am confuse about the rest of the calculation and how to display the total

  3. #3
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    Compute the tax in simple maths terms... then printf the result with printf().

    Something like
    >printf ("Sale Amount: %f plus %f tax is %f\n", SaleAmount, Tax, SaleAmount+Tax);

    There's somethings you'll need to learn about formatting of the output, but I'll let you find that out for yourself

    Also, have a read of this.
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  4. #4
    Casual Visitor
    Join Date
    Oct 2001
    Posts
    350
    Likely a bug filled masterpiece, but perhaps it *might* help.

    Code:
    #include <stdio.h>
    
    
    int main(void)
    {
       const float salesTax = 0.06;
       float prices[3] = { 3.99, 2.75, 1.35 };
       float subTotal, total;
       int selection;
    	
       subTotal = 0.0;
       total = 0.0;
    	
       printf("1> wrench $3.99\n");
       printf("2> socket $2.75\n");
       printf("3> wood   $1.35\n");
       printf("\n--> ");
    	
       scanf("%d", &selection);
    	
       subTotal = prices[selection - 1];
    	
       total = (subTotal * salesTax) + subTotal;
    	
       printf("\nFor item purchased, you owe %.2f\n", total);
    	
    	
       return 0;
    }
    Of course you'd have to check it for data input that is out of range.
    Last edited by ronin; 09-15-2002 at 07:44 PM.
    I haven't used a compiler in ages, so please be gentle as I try to reacclimate myself. :P

  5. #5
    Lead Moderator kermi3's Avatar
    Join Date
    Aug 1998
    Posts
    2,595
    In the future please use code tags when posting code. I added them for you this time. People are MUCH more likely to help you if you use them.

    Info on code tags may be found here:

    http://www.cprogramming.com/cboard/s...threadid=13473
    Kermi3

    If you're new to the boards, welcome and reading this will help you get started.
    Information on code tags may be found here

    - Sandlot is the highest form of sport.

  6. #6
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    Kermi, that link you posted is broken.

    Use this one:
    http://www.cprogramming.com/cboard/s...threadid=13473
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Code Check
    By Dae in forum C++ Programming
    Replies: 12
    Last Post: 01-08-2009, 06:01 PM
  2. HELP!!!!emergency ~expert please help
    By unknowppl in forum C Programming
    Replies: 1
    Last Post: 08-19-2008, 07:35 AM
  3. << !! Posting Code? Read this First !! >>
    By kermi3 in forum Game Programming
    Replies: 0
    Last Post: 10-14-2002, 01:27 PM
  4. << !! Posting Code? Read this First !! >>
    By kermi3 in forum C# Programming
    Replies: 0
    Last Post: 10-14-2002, 01:26 PM
  5. Check my code Please
    By AdioKIP in forum C++ Programming
    Replies: 1
    Last Post: 03-12-2002, 07:52 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21