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 trialTim Groot
1,334 PointsStuck
Hi Guys, just got started yesterday and it all went pretty good so far but i'm stuck now. Could somebody explain what they are asking in a bit more detail?
This is the question:
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. (No need to write the main function. Just write out the implementation for the addTwo function.) __
My thoughts so far:
If I want to make a function like this I have to know the two floats right?
Any help or further explanation is greatly appreciated.
Br, Tim
3 Answers
Joshua O'Connor
Courses Plus Student 3,207 PointsImagine you have two existing floats already, for arguments sake:
float a = 1.1; float b = 2.2;
Now just write the rest of the code that would return the sum of these in the challenge (I'll include an example in case I'm not being clear).
Your code in the challenge should look similar to this:
float addTwo (float a, float b);
float addTwo (float a, float b){
return a + b;
}
Whoops sorry someone already answered (since I can't delete this I'll just leave it here)
Adrian Carballo
6,311 PointsYou don't really need to know the values, all you need is a variable for them, and you can define your function in terms of those variables. For example, say you name your variables a and b, the function should look like
addTwo(a, b) {
return a + b;
}
Just need to add the type for the variables depending on the language you want to code it on.
Tim Groot
1,334 PointsWOOO!
Thanks guys, really appreciate your help.