Thread: can someone help me with my code

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

    can someone help me with my code

    I am new to C I am trying to do 2 functions. I want a user to enter a price and then my main function send my total cost that calculates sales tax and then have my main function call a function that will display the sales tax due and total cost. I have revised my code and now i am getting an error that says expected primary expression before float. I tried looking it up but still cant understand. here is my code.

    Code:
    #include <stdio.h>
    float askprice();
    float addtax();
    void printtotal(float total);
    
    int main()
    
    {
    
    float price;
    float tax;
    float total;
    
    price = askprice();
    tax = addtax();
    
    
    
     total= (price * tax);
    
    
    
    
    
    
    
    
    
    
    
    
    return 0;  }
      float askprice()
    
    
    
    {float price;
    printf("Please enter a price");
    scanf("%f",&price);
    
    return price;
    
    }
    
    
    float   addtax(float tax,float price)
    
    
     { float total;
     total= price*tax
     return total;
    
    }
    
      void printtotal(float total)
     { 
        printf("\n The total is %f",total);
     }

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    38,169
    Well the most immediate problem is the ; missing on line 50.

    After that, you need to resolve this inconsistency.
    float addtax();
    tax = addtax();
    float addtax(float tax,float price)


    Then you need to figure out some means of actually inputting a value for tax.

    Also, decide whether main() or addtax() perform this calculation:
    total= (price * tax);

    You're doing it twice at the moment.

    I suppose print the total would be good as well.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,793
    And use some autoformatter - it will help you to find problems in your code

    Code:
    #include <stdio.h>
    
    float askprice();
    float addtax();
    void printtotal(float total);
    
    int main()
    {
        float price;
        float tax;
        float total;
    
        price = askprice();
        tax = addtax();
    
        total= (price * tax);
    
        return 0;
    }
    
    float askprice()
    {
        float price;
        printf("Please enter a price");
        scanf("%f",&price);
    
        return price;
    }
    
    float   addtax(float tax,float price)
    {
        float total;
        total= price*tax
               return total;
    
    }
    
    void printtotal(float total)
    {
        printf("\n The total is %f",total);
    }
    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

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 09-19-2012, 01:58 PM
  2. Replies: 14
    Last Post: 04-01-2008, 02:23 AM
  3. producing c/c++ code from flowcharts,pseudo code , algorithims
    By rohit83.ken in forum C++ Programming
    Replies: 3
    Last Post: 02-20-2008, 07:09 AM
  4. Having trouble translating psudeo-code to real-code.
    By Lithorien in forum C++ Programming
    Replies: 13
    Last Post: 10-05-2004, 07:51 PM
  5. Replies: 0
    Last Post: 02-21-2002, 06:05 PM

Tags for this Thread