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) Fundamentals of C Variables

Laura Hill
Laura Hill
13,674 Points

Why is this output weird?

Im using XCode for Objective C basics.

Here is the code:

#include <stdio.h>

int main()
{

    int days_in_a_week = 7;
    float cm_to_in = 2.54;

    char the_w;
    the_w = 'W';

    // insert code here...
    printf("%days in a week.\n", days_in_a_week);
    printf("%f cm per in.\n", cm_to_in);
    return 0;
}

the output is cutting off the space and the letter D, in "days" WHY?? output:

7ays in a week.
2.540000 cm per in.
Program ended with exit code: 0

EDIT: I changed you tag so it highlights in the right way. Press EDIT and see what i did to achieve this -Aurelian

Try This:

printf("%d days in a week.\n", days_in_a_week);

Because the identifier for an integer is %d

Rashii Henry
Rashii Henry
16,433 Points

in your first printf function you simply didn't recognize that the %d(which is the identifier for an integer) was included along with the string you were trying to print.

However if you ever see a mistake like that again whenever your logging or printing results in the console look at the printed result and see where the error is, once it's spotted,

look back at the string you typed, within the same area should be your error.

Good Luck.

1 Answer

Laura Hill
Laura Hill
13,674 Points

Rashii, you're right. I need to move my chair closer:))