Amazon.com Widgets Chapter 13 Exercise 5
Welcome, Guest. Please login or register.
Did you miss your activation email?
May 19, 2013, 05:31:33 AM
Home Help Search chat Login Register   
News: Read this please.The Great Kangaroo Escape Looking for reviews of the 4th ed on Amazon!   Twitter:  @skochan
                     

+  Official Forum for Programming in Objective-C (the iPhone Programming Language) - Stephen Kochan
|-+  Programming in Objective-C, 4th edition
| |-+  Exercises
| | |-+  Chapter 13
| | | |-+  Chapter 13 Exercise 5
Pages: [1]   Go Down
Print
Author Topic: Chapter 13 Exercise 5  (Read 339 times)
clouded
Full Member
***
Posts: 123






« on: June 07, 2012, 11:40:42 AM »

Here's what I have on this exercise:

Code: (Objective-C)
//  Chapter 13 Exercise 5
// Write a typedef definition for a struct date called Date that enables you to
// make declarations such as
//   Date todaysDate;
// in your program.

//  main.m

#import <Foundation/Foundation.h>

int main (int argc, const char * argv[])
{

    @autoreleasepool {
        
        typedef struct date {
            int month;
            int day;
            int year;
        } Date;
        Date todaysDate;
        
        NSLog(@"Enter today's date: ");
        scanf("%i %i %i", &todaysDate.month, &todaysDate.day, &todaysDate.year);
        
        NSLog(@"todaysDate = %i/%i/%i", todaysDate.month, todaysDate.day, todaysDate.year);
        
    }
    return 0;
}

Output:

Enter today's date:
06 07 2012
todaysDate = 6/7/2012
Logged
mo7ionsickness
Jr. Member
**
Posts: 50






« Reply #1 on: August 28, 2012, 12:51:47 PM »

Code: (Objective-C)
#import <Foundation/Foundation.h>

int main(int argc, const char * argv[])
{

    @autoreleasepool {
       
        struct date
        {
            int month;
            int day;
            int year;
        };
       
        typedef struct date Date;
       
        Date todaysDate;
       
        todaysDate.month = 8;
        todaysDate.day = 28;
        todaysDate.year = 2012;
       
        NSLog(@"Today's date is %i/%i/%.2i", todaysDate.month,
              todaysDate.day, todaysDate.year % 100);
       
    }
2012-08-28 20:46:46.712 Test[1012:303] Today's date is 8/28/12
Logged
Pages: [1]   Go Up
Print
Jump to:  



Login with username, password and session length

Powered by MySQL Powered by PHP Powered by SMF 1.1.11 | SMF © 2006-2009, Simple Machines LLC Valid XHTML 1.0! Valid CSS!
Entire forum contents (c) 2009 classroomM.com. All rights reserved.