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 Conditionals - If-Else

Caleb Dismuke
PLUS
Caleb Dismuke
Courses Plus Student 190 Points

Output will not work

I practiced the "if, else" on my own. When I hit the play button, it said my build was successful, but the output bar went away and nothing was displayed. I was not prompted that there were errors in the code. Spent a while trying to figure out what happened. Any tips?

Thanks, Caleb

5 Answers

Peter Pult
Peter Pult
8,095 Points

The closing curly bracket should be after the line I mentioned min_value = 'b';. Otherwise the block will only be executed when - as you already recognized yourself - b is smaller or equal than a.

So it looks something like this:

if (a < b) {
    minimum = a;
    min_value = 'a';
} else {
    minimum = b;
    min_value = 'b';
}
    printf("%c %d is the minimum\n", min_value, minimum);

Hey Caleb!

Please could you post the code that you are having problems with?

-Luke

Caleb Dismuke
PLUS
Caleb Dismuke
Courses Plus Student 190 Points

int a = 11; int b = 9; int minimum; char min_value;

if (a < b) {
    minimum = a;
    min_value = 'a';
} else {
    minimum = b;
    min_value = 'b';

    printf("%c %d is the minimum\n", min_value, minimum);

the output works when b is less than a. When I make a less than b, blank screen. I am sure it is something minor, but my eyes cannot find it.

Thanks for the help.

Peter Pult
Peter Pult
8,095 Points

As far as I can see you are missing a curly closing bracket after your line min_value = 'b';

Caleb Dismuke
PLUS
Caleb Dismuke
Courses Plus Student 190 Points

Its there Peter, just right below the printf line, just does not show here.

Caleb Dismuke
PLUS
Caleb Dismuke
Courses Plus Student 190 Points

Peter, thank you very much, that was it. Grateful for the help.

Caleb

Peter Pult
Peter Pult
8,095 Points

Glad I could help. For clarity, please mark the question as answered. :)