For some reason I can't run this example, and I can't figure out why...

It has an issue with the 'reduce' method, with the debugger highlighting the "numerator /= u;" line.

In the console I get:

[Session started at 2009-03-09 11:36:06 +1100.]

2009-03-09 11:36:06.397 FractionTest[1287:10b] 1/4

2009-03-09 11:36:06.398 FractionTest[1287:10b] +

2009-03-09 11:36:06.399 FractionTest[1287:10b] 1/2

2009-03-09 11:36:06.400 FractionTest[1287:10b] =

[Session started at 2009-03-09 11:36:06 +1100.]

Loading program into debuggerâ€¦

GNU gdb 6.3.50-20050815 (Apple version gdb-962) (Sat Jul 26 08:14:40 UTC 2008)

Copyright 2004 Free Software Foundation, Inc.

GDB is free software, covered by the GNU General Public License, and you are

welcome to change it and/or distribute copies of it under certain conditions.

Type "show copying" to see the conditions.

There is absolutely no warranty for GDB. Type "show warranty" for details.

This GDB was configured as "i386-apple-darwin".Program loaded.

sharedlibrary apply-load-rules all

Attaching to program: `/Users/ash/Documents/Education/Obj-C Progs/FractionTest/build/Debug/FractionTest', process 1287.

Current language: auto; currently objective-c

(gdb)

Can someone please help me?

My code is:

// Fraction.m

#import "Fraction.h"

@implementation Fraction

@synthesize numerator, denominator;

- (void) print

{

NSLog(@"%i/%i", numerator, denominator);

}

- (double) convertToNum

{

if (denominator != 0)

return (double) numerator / denominator;

else

return 1.0;

}

- (void) setTo: (int) n over: (int) d

{

numerator = n;

denominator = d;

}

- (Fraction *) add: (Fraction *) f

{

Fraction *result = [[Fraction alloc] init];

int resultNum, resultDenom;

resultNum = numerator * f.denominator + denominator * f.numerator;

resultDenom = denominator * f.denominator;

[result reduce];

return result;

}

- (void) reduce

{

int u = numerator;

int v = denominator;

int temp;

while (v != 0) {

temp = u % v;

u = v;

v = temp;

}

numerator /= u;

denominator /= u;

}

@end

// FractionTest.m

#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 *bFraction = [[Fraction alloc] init];

Fraction *resultFraction;

// Set two fractions to 1/4 and 1/2 and add them together.

[aFraction setTo: 1 over: 4];

[bFraction setTo: 1 over: 2];

// Print the results

[aFraction print];

NSLog(@"+");

[bFraction print];

NSLog(@"=");

resultFraction = [aFraction add: bFraction];

[resultFraction print];

[[aFraction add: bFraction] print];

[aFraction release];

[bFraction release];

[resultFraction release];

[pool drain];

return 0;

}