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 Objective-C Basics (Retired) Functional Programming in C Functions

Oleksiy Ryabchuk
Oleksiy Ryabchuk
875 Points

sum of 2 floats func

what i do wrong? mb i need to return somth in body of main func?

functions.c
float addTwo(float a, float b);  //declare type name args
{
    float a = 15.2;    //declare variables
    float b = 1.5;
    printf("the sum is %f \n", addTwo); //print the result
    return 0;
}

float addTwo(float a, float b) {  // func that make a sum 
    return a + b;
}
Oleksiy Ryabchuk
Oleksiy Ryabchuk
875 Points

just create simple func like this

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

add pass the challenge, what is my problem with 1st function i tried it in xcode and have massage a and b is undefined but i declare it

1 Answer

Gabe Nadel
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Gabe Nadel
Treehouse Guest Teacher

int main(int argc, const char * argv[]) { @autoreleasepool { // insert code here... NSLog(@"Hello, World!"); }

float addTwo(float a, float b);  //declare type name args

float a = 15.2;    //declare variables
float b = 1.5;

float addTwoResult = addTwo(a, b); 

//create a variable to hold the result, call the function, set teh variable value to that result.

printf("the sum is %f \n", addTwoResult); //print the result


return 0;

}

float addTwo(float a, float b) { // func that make a sum return a + b; }

Oleksiy Ryabchuk
Oleksiy Ryabchuk
875 Points

thanx it works, now i understand mistake :)