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
Ludwing Najera
4,596 Pointswhy is float b undeclared?
so i was doing a challenge, and the debugger said that the float b is undeclared, am i crazy, or am i just missing one tiny thing?
int addTwo(float a, float b); int main(int argc, const char * argv[]); {
float Moo = 90;
float Foo = 58;
int addTwo(moo, foo);
int lots = addTwo(moo, foo) * addTwo(moo, foo);
printf(" whaaaaa? %f\n", addTwo(moo, foo);
return 0;
}
int addTwo(moo, foo) { return a + b;
}
2 Answers
RASHU BHATNAGAR
Courses Plus Student 2,669 PointsHi Ludwing, In the definition of addTwo(moo, foo) function, You have declared two variables moo and foo, so the compiler will only recognize these two variables. Instead of writing : return a+b; // a and b are not declared in the function. you should write : return moo+foo; then the function should work fine. Then two the function would probably not work fine look at the line you have written for the printf printf(" whaaaaa? %f\n", addTwo(moo, foo); instaed you should write printf(" whaaaaa? %f\n", addTwo(moo, foo)); // the parenthesis for the printf statement is missing.
I hope it helps.
Ludwing Najera
4,596 Pointsi copied it off of this code and i did just the same thing on the other and just replaced ints with floats
int funky_math(int a, int b);
int main()
{
int foo = 24;
int bar = 35;
int result = funky_math(foo, bar);
int lots = funky_math(foo, bar) * funky_math(foo, bar);
printf("funky math %d \n", lots);
return 0;
}
int funky_math(int a, int b) { return a + b + 343; }
I'm sorry it did not work D:
agreatdaytocode
24,757 PointsLudwing you have declared Foo and bar change them to a and b.
int a = 24;
int a = 35;
Also change the rest of the "foo & bars" to a | b
I hope that helps.
agreatdaytocode
24,757 PointsWhat challenge are you working on?
agreatdaytocode
24,757 Pointsagreatdaytocode
24,757 PointsYou could change it to return Moo + Foo. If you would like to return a + b see Rashu post below :)