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 trialMike Agamaite
163 PointsWhat are you looking for
int addTwo(float a, float b); int main() { float first = 24; float second = 35;
printf("sum %d\n", addTwo(first, second));
return 0;
}
int addTwo(float a, float b) {
return a + b;
}
my code works but the checker does not like it so I am not sure what it is looking for
1 Answer
Guillaume Maka
Courses Plus Student 10,224 Pointsfloat addTwo(float a, float b) {
return a + b;
}
//not need for the challenge
printf("sum %f\n", addTwo(10.0, 10.0);
and don't write the "main" function for the challenge just the "addTwo" function
Unsubscribed User
15,508 PointsUnsubscribed User
15,508 PointsYou fell in to the same mistake I did. It's quite a silly one when you look back at it. You set your arguments up correctly defining them as both floats. What you've forgotten to do (like I did) is that you've defined the function as an integer instead of a float. So whilst the arguments being taken in are floats, it's never going to return anything as a float because the function itself is an integer. This needs to be changed to a float. So, the correct code would be:
float addTwo
not:
int addTwo
I hope this makes sense!