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

Code Challenge: Functions [Problem Solved]

I'm stuck at this challenge from Objective-C Basics. It's asking to 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.

// I don't really know what they mean by float numbers, but can't find the way through this code, thought I was doing it right...

My code:

int addTwo(int a, int b);
int main()
{
    int hi = 22;
    int ho = 24;
    printf("addTwo %d", addTwo(hi, ho));

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

2 Answers

float is a primitive data type. It is a number that contains decimals. you have the right idea, you just need to change all your ints to floats

for example

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

Ohh! my fail, I think I must rest ^^ Forgot about the float variables.

Int - Float - Char

Thank you Stone! Really appreciate your help :)

haha no problem.

wish I had found this before I tried what felt like a thousand other options I went through. I didn't realize the challenge wanted the variable "addTwo" to be created as a float, so I put the following as my first attempt.

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