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 trialkirkbyo
15,791 PointsWhat am I doing wrong?
I hate to post the same question twice, but I am still having the same problem. Alright I don't know what to do when they ask me to return the sum of two floats. I get that I have to use the return function, but I don't get if I am supposed to write it with the "int" function or the "float" function. If anyone could help me out that would be greatly appreciated
Here is the code, I am using
float addTwo(float a, float b);
{
float foo = 24;
float bar = 35;
float result = addTwo(foo, bar );
printf("Add Two %d\n", result);
return 0;
}
float addTwo(float a, float b) {
return a + b;
}
2 Answers
Ben Hopkins
Full Stack JavaScript Techdegree Student 2,348 PointsOkay so, you've written out a whole lot more than the challenge wants. It just wants the implementation of the addTwo function.
The float before the addTwo function tells the compiler that the function should return a float.
The word float before each argument tell it that each argument should also be a float.
You do not need to identify a data type when using "return".
The challenge tells you to miss out the main function part. so for the challenge you will just need to put the last bit:
float addTwo(float a, float b) {
return a + b;
}
Bruno Calheira
12,625 PointsThe error is the ; at end of the first line
kirkbyo
15,791 Pointskirkbyo
15,791 PointsThanks so much for you're help!