Amazon.com Widgets Error in example 7.6 example in 3rd edition book?
Welcome, Guest. Please login or register.
Did you miss your activation email?
June 19, 2013, 07:59:22 PM
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
| | | |-+  Error in example 7.6 example in 3rd edition book?
Pages: [1]   Go Down
Print
Author Topic: Error in example 7.6 example in 3rd edition book?  (Read 591 times)
dharr19
Full Member
***
Posts: 175


Email




« on: July 17, 2011, 11:36:41 AM »

#import <Foundation/Foundation.h>
#import "Fraction.h"

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

    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
    Fraction *aFraction = [[Fraction alloc] init];
    Fraction *sum = [[Fraction alloc] init], *sum2;  << sum2 declared here
    int i, n, pow2;
   
    [sum setTo:0 over:1]; // set first fraction to 0
   
    NSLog(@"Enter your value for n:");
    scanf("%i", &n);
   
    pow2 = 2;
    for( i = 1; i <= n; ++i)
    {
        [aFraction setTo:1 over:pow2];
        sum2 = [sum add:aFraction]; 
        [sum release];
        sum = sum2;
        pow2 *= 2;
       
    }
   
    NSLog(@"After %i iterations, the sum is %g", n, [sum convertToNum]);  << I get the error Assigning from incompatible type void
    [aFraction release];
    [sum release];
   
    [pool drain];
    return 0;
}
Logged
bpedit
Jr. Member
**
Posts: 65


Email




« Reply #1 on: July 17, 2011, 12:36:39 PM »

It looks to me like you've entered the code into main properly. Since this program worked for me, I'd say your problem is outside of main. Check your Fraction files and make sure your convertToNumber method is returning a "double" type .
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.