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 trialhasanmak
424 Pointsi have no idea how to write this code at all
Write a function named "addTwo" that accepts two float numbers as arguments. The function should also return a float which is the sum of the two arguments passed to the function.
Amit Bijlani or Douglass Turner can you please show me the answer because i don't know how By the way I'm 11 years old
6 Answers
Stone Preston
42,016 Pointswriting a function usually looks something like this
returnType functionName(dataType arguementOne, dataType argumentTwo) {
//do whatever you need to do
return something;
}
the question gives you the return type, the function name, the datatype and number of arguments and tells you what you need to do inside the body of the function (return a float thats the sum of two arguments).
Thomas Nilsen
14,957 PointsTry watching the video one more time.
It should be something like this:
<return type> <name of function> (<datatype> argument1, <datatype> argument2){
return (argument1 + argument2);
}
Taylor Hammons
1,609 PointsI'm having trouble with this challenge as well. I typed: float addTwo(float a, float b) { return (a + b); } //and it isn't working.
Fuad Adetoro
6,490 PointsThat is correct move on from the section until it's fixed
Fuad Adetoro
6,490 PointsThats correct but there shouldnt be no parentheses in the return... so { return a + b; } also theres something wrong with the challenege ATM
hasanmak
424 Pointsok thanks
Amit Bijlani
Treehouse Guest TeacherSome recent changes to challenge broke it. Sorry about the inconvenience but it should work now.