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 trial

General Discussion

In objective c basics stuck on this challenge . cannot go any further and unlike codeschool this won't give you any hint

Challenge Task 1 of 1

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.)

no idea how to finish this and doesnt give any hints or answer like codeschool so am I jsut stuck forever lol?

1 Answer

Maybe I can help you out a bit here. The challenge is asking you here to implement a function that adds up two float variables without writing out the main function, which could be tricky considering the call to the addTwo function needs to be named in the main(). I will be using the // to make comments as you would in the code.

// Firstly, we need to define the two floats. I made up the numbers in this example. Normally these are defined in the main function before the call for the addTwo function is made


float firstNumber = 2.512342;
float secondNumber = 4.523453;

// Now here is where we implement the 'addTwo' function which would be theoretically located outside of the main(). FYI, you see the ';' missing at the end of the function? That is correct, it's not a typo.

float addTwo(float firstNumber, float secondNumber)

{
float sumOf = firstNumber + secondNumber;
return sumOf;
}

That's basically it. I haven't gotten to that challenge yet in my progress so I wouldn't know how they want it written out (the video might give some context as I've noticed that the challenges are nearly identical to the content of the respective video). But I'm also studying another book on C and Obj-C and I'm a bit further than where you're at right now. Hope this helps.

-Jeremy

thanks that actually made it alot more clear. I am taking a class and we are well beyond this but nothing really sunk in and now I have a project due next thursday making what would seem to be a simple survey in ios with objective c. I have been cramming all week and went through the complete track of objective c on codeschool and now hoping to get as far as I need to with tree house to be able to finish this project. I made it past this challenge now thanks again for the help.