Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS

Alex Ferguson
Alex Ferguson
2,518 Points

Keep getting an error in C

Ok I'm trying to do these C practice exercises from this book and I keep getting this "Expected identifier or '('" error, this is what I wrote so far:

#include <stdio.h>

float fahrenheitFromCelsius(float cel);

{               //<-this line where the error shows up with the red stop sign

    float fahr = cel * 1.8 + 32.0;
    printf("%f Celsius is %f Fahrenheit.\n", cel, fahr);
    return fahr;

}

int main(int argc, const char * argv[])

{

    float freezeInC = 0;
    float freezeInF = fahrenheitFromCelsius(freezeInC);
    printf("Water freezes at %f degrees Fahrenheit.\n", freezeInF);

    return 0;
}

1 Answer

Remove the semicolon after the line float fahrenheitFromCelsius(float cel);. A semicolon ends statement, so you're getting that error because you're ending the function body before it begins.