My Blog List

Tuesday, December 7, 2010

Hey Buddy - Some Input Would be Nice Here!

Version:1.0 StartHTML:0000000187 EndHTML:0000040872 StartFragment:0000002853 EndFragment:0000040836 SourceURL:file://localhost/Users/Laurel/Apps%20Learning/JournalTravelToInput.doc
Though I won’t be scanning for input this way (I think it’s done with scripting), I really don’t like hard coding data values in. It just BUGS me. So I wanted to see how to accept user input. It wasn’t in my Holzner Quick Start Objective C book at all. That made me feel like I was working in some kind of closed system. Output yes – but never any input!

Several bugs later, all of which reinforced for me that abundant practice with basic syntax is always valuable, I am accepting and using user input in this console-like fashion.

The book that I found scanf in is Programming in Objective-C 2.0 by Stephen G. Kochan from my public library.



Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "x86_64-apple-darwin".tty /dev/ttys001
Loading program into debugger…
Program loaded.
run
[Switching to process 1126]
Running…
2010-12-07 21:43:28.187 TTravINPUTYearsDraft1[1126:a0f] What year do you want to travel to?
1893
1893 is a great travel destination!
  .... 
 Consider purchasing travel INSURANCE for your trip to 1893
Please proceed to ticketing for your trip from the year 2010 to the year 1893
Thank you for selecting PORTAL PILOTS for your time travel needs!

Debugger stopped.
Program exited with status value:0.


// TTravINPUTYearsDraft1
//  Let's see if we can share .h and .m with another project
//  I opened that project up
//  NOPE need my own
// BASED ON TTravelToAndFrom
// Based on review of ideas page 92 Quick Start Objective C


#include "TTravINPUTDraft1.h"

#include <stdio.h>

#import <Foundation/Foundation.h>



//Main

int main (void) {
   
    // instantiate the objectPortal Time Travel Portal
   
    TravelPeriod *objectPortal = [TravelPeriod new];
   
    //int n, number, triangularNumber;
   
    int year1Input;
    NSLog(@"What year do you want to travel to?\n");
   
    scanf ("%i", &year1Input);
     printf("%i is a great travel destination!\n", year1Input);
           
    printf ("\f .... \f Consider purchasing travel INSURANCE for your trip to %i \n", year1Input);
   
    //[objectPortal setYears:2010 second:1893];
    [objectPortal setYears:2010 second:year1Input];

    printf("Please proceed to ticketing for your trip from the year %i ", [objectPortal yearValue1]);
    printf("to the year %i\n", [objectPortal yearValue2]);
    printf("Thank you for selecting PORTAL PILOTS for your time travel needs!\n");
    return 0;
}