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 trialRoger Green
643 PointsFunction
im suppose to create a function that returns a float. I don't know were I went wrong. int addTwo (float a, float b); float goku = 4.4; float vegeta = 6.6; printf("addTwo %f", addTwo(goku, vegeta));
int addTwo (float a, float b); return a + b + 7;
6 Answers
Vladimir Cezar
7,710 PointsIf a function returns a float it needs to be be declared as it. So, instead of
int addTwo (float a, float b);
you should write
float addTwo (float a, float b);
Vladimir Cezar
7,710 PointsYour function declaration is also wrong. here is the full, corrected, code:
int main(int argc, const char * argv[])
{
float addTwo (float a, float b);
float goku = 4.4;
float vegeta = 6.6;
printf("addTwo %f", addTwo(goku, vegeta));
return 0;
}
float addTwo (float a, float b){
return a + b + 7;
}
Roger Green
643 PointsImplement a function named "addTwo" that returns the sum of two floats. The function will accept two float numbers as arguments. It should add the two arguments together, and return the result. (No need to write the main function. Just write out the implementation for the addTwo function.)
This is the main goal. I tried what you showed me but it came up with the same error.
Vladimir Cezar
7,710 PointsOk, here it is.
float addTwo (float a, float b){
return a + b;
}
Copy and paste exactly what is above and ONLY that. It works.
Roger Green
643 PointsSo the { } are super important in functions?
Vladimir Cezar
7,710 PointsYes. Curly brackets define a block of code. Without it an C function would not know where to start or begin. Please consider to accept the answer.
Roger Green
643 PointsCool thanks for your help
Vladimir Cezar
7,710 PointsIf this answer your question would you please mark the answer as 'Best answer'? It helps with my scoring. Thanks.
Vladimir Cezar
7,710 PointsSure. Don't forget to mark the answer as *'Best Answer'*
Roger Green
643 PointsRoger Green
643 PointsI tried what you said but it continues to say this:
expected function body after function declarator return a + b + 7.8; ^ 2 errors generated.