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

Girri M Palaniyapan
Girri M Palaniyapan
7,829 Points

What happens if we want multiple integers to be printed in a statement? How would the syntax be different?

Supposing I have

int days_in_a_week = 7; int hours_in_a_day = 24;

How can I express both these int using %d?

Thanks :)

Ryan Jin
Ryan Jin
15,337 Points

In swift, you just simply add () outside the variable or constant you want to display. So it should look similar to

// Swift
var mInt = 18
var mAnotherInt = 19
print("First one is\(mInt). The second one is \(mAnotherInt)")

In objective C, it is kind of different, instead, you add %d in the string where you want to display your data, and the second %d will require you to add a second argument. So it will look like

Int mInt = 18;
Int mSecondInt = 19;
NSLog(@"The first one is %d, and the second one is %d", mInt, mSecondInt);

1 Answer

Hi there, I guess you want to display both days_in_a_week and hours_in_a_day using the same output statement. Well if that is the case, it can be done as:

printf("There are %d days in a week and %d hours in a day",days_in_a_week,hours_in_a_day);

Hope this helps :)