Amazon.com Widgets Program 6.10/6.10A missing }
Welcome, Guest. Please login or register.
Did you miss your activation email?
April 21, 2014, 12:17:05 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
|-+ Old Stuff
| |-+ Errata
| | |-+ 1st Printing
| | | |-+ Program 6.10/6.10A missing }
Pages: [1] Go Down
Print
Author Topic: Program 6.10/6.10A missing } (Read 884 times)
ToddSternisha
Newbie
*
Posts: 2






on: December 08, 2011, 03:23:46 PM

Program 6.10's inner loop is missing its closing curly brace in the eBook versions, which keeps it from building successfully. Here is a corrected version:
Code: (Objective-C)
//  Program to generate a table of prime numbers

#import <Foundation/Foundation.h>

int main (int argc, const char * argv[])
{
    @autoreleasepool {
        int   p, d, isPrime;
        
        for ( p = 2; p <= 50; ++p ) {
            isPrime = 1;
            
            for ( d = 2; d < p; ++d ) {
                if ( p % d ==0 )
                    isPrime = 0;
            }   // This line is missing from the eBook example
                
            if ( isPrime != 0)
                NSLog(@"%i ", p);
        }
    }
    
    return 0;
}
Last Edit: December 08, 2011, 03:40:44 PM by ToddSternisha Logged
ToddSternisha
Newbie
*
Posts: 2






Reply #1 on: December 08, 2011, 03:42:12 PM

The same issue, of course, applies to Program 6.10A:
Code: (Objective-C)
//  Program to generate a table of prime numbers
//  second version using BOOL type and predefined values

#import <Foundation/Foundation.h>

int main (int argc, const char * argv[])
{
    @autoreleasepool {
        int     p, d;
        BOOL    isPrime;
        
        for ( p = 2; p <= 50; ++p ) {
            isPrime = YES;
            
            for ( d = 2; d < p; ++d ) {
                if ( p % d ==0 )
                    isPrime = NO;
            }   // This line is missing from the eBook example
                
            if ( isPrime == YES )
                NSLog(@"%i ", p);
        }
    }
    return 0;
}
Logged
skochan
Administrator
Hero Member
*****
Posts: 3114







Reply #2 on: December 13, 2011, 02:21:18 PM

Yes, you're right.  Thanks!
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.