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 trialJeffrey Lawlis
374 PointsI don't even know where to start
So far I have:
1 float aly[] = {1.5, 2.5}; 2 int sum
2 Answers
Dane Parchment
Treehouse Moderator 11,077 PointsWell first of all let's start by getting you to write a function.
It is a function that asks for a float so lets start by writing a simple empty function to outline this the name is already specified by us, so let's name the function addTwo
float addTwo() {
}
Now we need to look at what it is asking us to do: "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." So let's begin by adding to parameters to this function, I will call them float x, and float y
float addTwo(float x, float y) {
}
Now the instructions state that it wants us to return the sum of these two floats, so let's do that
float addTwo(float x, float y) {
return x + y;
}
And you are done! See? Not too hard ;) I recommend that you go back and re-watch the videos, so that you can understand how to write functions properly, especially if you were completely lost. Take it slow and you will finally get it :)
Jeffrey Lawlis
374 PointsDane,
Thank you very very much for such a long detailed explanation. I've watched that video several times and no where in there does it discuss "return" functions. Also, I don't think we've moved into Objective-C yet. Are these return functions exclusive to Objective-C or can you also do them in C? Thanks again!
Respectfully,
Jeff
Dane Parchment
Treehouse Moderator 11,077 PointsThe return statement at least in my experience seems to be in any computer language that supports functions. I haven't done the IOS track on Treehouse (I don't have a mac) so I didn't know that it did not cover functions at that point.
Glad I was of help though! :)