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

iOS

functions code challenge

cant seem to figure out why im not able to complete this code challenge. here is what it wants me to do and what i put....

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.

int addTwo (float a, float b);
int main () 
{
    float ha = 3.2;
    float ja = 5.5;
    printf ("ha ja %f/n", addTwo(ha, ja));
return 0;
}

int addTwo (float a, float b){
    return a + b;
}

it keeps telling me....

Make sure you've defined the return type and both paramter types as 'float' and that you are returning the result.

4 Answers

Check your function's return type. In the code you posted, it's not returning a float.

Your addTwo function is currently of type int. Change it to type float.

float addTwo (float a, float b) {
    return a + b;
}
Amit Bijlani
STAFF
Amit Bijlani
Treehouse Guest Teacher

The code challenge simply needs to see the implementation of the function. You need not write the main function because it is not asking you to print out the values. Your answer is what Michael Reining wrote.

Thanks for the help guys! much appreciated! i got it all cleared up now!

Thanks again Amit Bijlani, Michael Reining, and Ben Rubin.