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 trialGirri M Palaniyapan
7,829 PointsWhat 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 :)
Girri M Palaniyapan
7,829 PointsThanks Ryan and Abhishek!
1 Answer
kasaltrix
9,491 PointsHi 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 :)
Ryan Jin
15,337 PointsRyan Jin
15,337 PointsIn swift, you just simply add () outside the variable or constant you want to display. So it should look similar to
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