function declaration issues

This is a discussion on function declaration issues within the C Programming forums, part of the General Programming Boards category; this is just a small portion of a program i'm working on, but i'm not really sure what im doing ...

  1. #1
    Registered User
    Join Date
    Feb 2011
    Posts
    42

    function declaration issues

    this is just a small portion of a program i'm working on, but i'm not really sure what im doing wrong with the declaration and use of these functions.. I "understand" what its telling me, but not sure how to fix the errors at the bottom of the page. any suggestions?? thanks..


    Code:
    float CalcGross(float hrsWkd, float payrate);
    float CalcFICA(float ytd, float gross);
    
         float CalcGross(float hrsWkd, float payRt)
            {
                    float gross = (hrsWkd * payRt);
                    return gross;
            }
    
            float CalcFICA(float ytd, float gross)
            {
                    if(ytd >= 67000.00)
                            ficaTax = 0.00;
                    else if ((ytd + gross) <= 67000.00)
                            ficaTax = (gross * ficaRate);
                         else ficaTax = (67000.00 - ytd) * ficaRate;
    
                    return ficaTax;
    
            }

    lab2.c: In function ‚main‚:
    lab2.c:70: error: static declaration of ‚CalcGross‚ follows non-static declaration
    lab2.c:16: error: previous declaration of ‚CalcGross‚ was here
    lab2.c:76: error: static declaration of ‚CalcFICA‚ follows non-static declaration
    lab2.c:17: error: previous declaration of ‚CalcFICA‚ was here

  2. #2
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Do you by any chance have these program statements inside your main() function?

    If so, you should know C does not support nesting of function definitions. That is, you can't define a function inside a function. Try moving the two function definitions above main() on your page and eliminating the declarations altogether.

  3. #3
    Registered User
    Join Date
    Feb 2011
    Posts
    42
    thats exactly what the problem was. i had the functions inside main. thanks for the help!!!

  4. #4
    Registered User
    Join Date
    Dec 2010
    Posts
    31
    It seems like you're not posting all of your code. I would not expect these
    errors from this code frag.

  5. #5
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by kona49er View Post
    It seems like you're not posting all of your code. I would not expect these
    errors from this code frag.
    True he shold have posted more of his code...

    I took the hint from the error messages ... "In function main..."

  6. #6
    Registered User
    Join Date
    Dec 2010
    Posts
    31
    Too bad the compiler did not produce a better diagnostic.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. OpenGL DC Buffer Renders slow
    By Lane the Great in forum Game Programming
    Replies: 10
    Last Post: 01-07-2011, 07:52 PM
  2. <Gulp>
    By kryptkat in forum Windows Programming
    Replies: 7
    Last Post: 01-14-2006, 01:03 PM
  3. Replies: 18
    Last Post: 12-31-2005, 01:56 PM
  4. C++ compilation issues
    By Rupan in forum C++ Programming
    Replies: 1
    Last Post: 08-22-2005, 06:45 AM
  5. Please Help - Problem with Compilers
    By toonlover in forum C++ Programming
    Replies: 5
    Last Post: 07-23-2005, 11:03 AM

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