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 trialjohn eee
117 PointsNot really sure what the question is asking tbh.
?
void addTwo(x,y){
float sum,x,y;
sum = x + y;
return sum;
}
2 Answers
Stone Preston
42,016 Pointsyou are close, however you have some errors:
void addTwo(x,y){
float sum,x,y;
sum = x + y;
return sum;
}
in your function above, you have a return type of void (which means it does not return anything), however you should return a float.
also, your parameters are missing their types.
in the first line, you declare a float called sum, and then two floats x and y. you dont need to declare the floats x and y, they are already declared as parameters.
here is a shell of what your function should look like:
returnType functionName(dataType parameterOne, dataType parameterTwo) {
return something;
}
using the function above as a guide, we can implement a function that returns a float, has 2 float parameters, and returns the sum of the 2 parameters:
float addTwo(float x, float y) {
float sum;
sum = x + y;
return sum;
}
john eee
117 PointsWow thanks a lot! :)
john eee
117 Pointsjohn eee
117 PointsImplement 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. (No need to write the main function. Just write out the implementation for the addTwo function.)