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 trialHumza Choudry
237 PointsImplement a function named "addTwo" that returns the sum of two floats as arguments.
Implement 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. I know this is very basic is simple yet it bothers me that why its not going through. I have also tried.. float addtwo(float a, float b) { a = 23; b = 34; return float a + b; }
float addtwo(float 10, float 21) {
return 10 + 21;
}
3 Answers
lideo
12,662 PointsYou can't use actual numbers as function arguments in your function definition.
float addTwo(float a, float b) {
return a + b;
}
joel bindi
11,923 PointsYou are correct maybe, but dont use actual numbers. "x" and "y" instead
float addTwo = (x,y) { return x + y; };
Humza Choudry
237 PointsThanks
Humza Choudry
237 Points:D Why is that they are not clear on that, it clearly say add two arguments. Also what is the purpose of having float in the parentheses (float a, float b). Is there another way this could have been done?