Thread: VAT Calculation

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

    VAT Calculation

    Hi. Only being pragramming for a few weeks now, hence the questions.

    For our latest assignment, we have been giving three codes to write, one of which is required to take price and VAT, and calculate the total cost. Here is the code so far:

    Code:
    /* VAT Calculation*/
    /* By Luke Sowersby */
    /* 05/03/08 */
    
    #include <stdio.h>
    #include <conio.h>
    #include <string.h>
    
    main()
    {
    float vat, price;
    
    printf("Please enter the VAT percentage:\n");
    scanf("%f",&vat);
    printf("Please enter the item value:\n");
    scanf("%f",&price);
    
    float price_to_cost_conversion(price, vat)
    {
    float cost;
    cost=((1+(vat/100))*price);
    return cost;
    }
    
    printf("The total price is %f",price_to_cost_conversion);
    }
    I was just hoping someone could point me in the right direction please, as to were i am going wrong.

    Thanks,

    Luke.

  2. #2
    Registered User
    Join Date
    Mar 2009
    Posts
    19
    Also, note that the following code:

    Code:
    printf("The total price is %f",price_to_cost_conversion);
    Is producing the following output:

    "The total price is 0.0000" so i'm thinking the error lies within the function?

  3. #3
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    you have a body of the function instead of the call to this funtion

    take body of it - out of main, and call it before printing the result
    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

  4. #4
    C / C++
    Join Date
    Jan 2006
    Location
    The Netherlands
    Posts
    312
    And another tip: indent your code (use tabs), like:

    Code:
    if(a == b)
    {
        printf("a is equal to b");
    }
    main() returns an int:

    Code:
    int main()
    {
        // your code
        return 0;
    }
    You don't need conio.h in this piece of code, so why include it? Also note that conio.h isn't standard.
    Operating Systems:
    - Ubuntu 9.04
    - XP

    Compiler: gcc

  5. #5
    Registered User
    Join Date
    Mar 2009
    Posts
    19
    Finally got the program working with some additional features. Thanks for the help.

    I usually do indents after i've finished experimenting with the code, and the libaries/titles at the top are what i c+p for each code i've been doing so far.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Date calculation program
    By putty88 in forum C Programming
    Replies: 5
    Last Post: 04-17-2009, 07:24 AM
  2. Problem with modulo calculation
    By manutdfan in forum C Programming
    Replies: 6
    Last Post: 01-12-2009, 03:37 PM
  3. C# calculation problem
    By Diablo02 in forum C# Programming
    Replies: 13
    Last Post: 10-25-2007, 08:42 PM
  4. Help with calculation and loop
    By Betty in forum C Programming
    Replies: 7
    Last Post: 04-10-2006, 05:37 AM
  5. help with pay calculation program
    By shugstone in forum C++ Programming
    Replies: 2
    Last Post: 02-17-2003, 09:38 AM