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 trialRami Ammoun
7,468 PointsStuck in the Objective of this stage
Hi, I know the solution might be quite simple, but i've been trying for almost an hour. I tried to look into the forms for a solution, nothing worked, and I gave up.
My code for the addTwo function were as follows:
int addTwo(float first, float second){ float first = 1.0; float second = 2.0; float sum = first + second; return sum; }
any solutions please?
3 Answers
Rami Ammoun
7,468 PointsThis code worked:
float addTwo(float first, float second){
float sum = first + second;
return sum;
}
Mikael Enarsson
7,056 PointsNick is almost right, but you also have to change the return type to float.
Rami Ammoun
7,468 PointsHi Mikael, I tried the code Nick suggested and I received an error:
"Bummer! The function does not appear to be returning the correct value. Is the return type a float?"
Can you tell me how to change the return type to float? I appreciate ur help
Nick Janes
5,487 PointsAs you can see, you already defined float first and second as parameters. Remove this:
float first = 1.0;
float second = 2.0;
If you did that, you should have this:
int addTwo(float first, float second){
float sum = first + second;
return sum;
}
This should give you the desired result! Let me know if you have anymore questions.
Rami Ammoun
7,468 PointsThank you Nick,
I still get the following error:
"Bummer! The function does not appear to be returning the correct value. Is the return type a float?"
Rami Ammoun
7,468 PointsI found the solution, I just had to change the 'int' in the declaration to float
the code was as follows:
float addTwo(float first, float second){
float sum = first + second;
return sum;
}
Thanks for your help!
Mikael Enarsson
7,056 PointsMikael Enarsson
7,056 PointsOps, sorry for not getting back to you, I totally missed your answer. Good job solving it though!!
ruo pu koh
2,669 Pointsruo pu koh
2,669 PointsWhere did the function float come from!?
Reading this codes makes sense. But it looks nothing like any of the tutorials from the video.
so confused...