Yep, here's a little project where I'm trying to get values out of Pascal's triangle using this equation as the basis:
I have 2 questions if anyone feels up to it:
1. Is their a Cocoa/C function that already does ! multiplications/iterations so I can ditch my for loops.
2. When my row values get near the 35th row and above it falls apart... I get 'Inf' returns in my field..... Is this an error in the function? or is the number too big to be held in the variable?
Thanks in advance anyone who can help.
------------------------------------------------------------------------------
#import "rowlController.h"
@implementation rowlController
- (IBAction)myTriangle

id)sender
{
float spac, fill, leftover, a, b, c, i, tote;
NSString *overError = @"'Filled' must be = or < 'Spaces'.";
spac = [theSpaces floatValue];
fill = [theFilled floatValue];
leftover = spac - fill;
if(leftover == 0)
{
leftover = 1;
}
a = 1;
b = 1;
c = 1;
if (spac>=fill)
{
for (i=1;i<(spac+1);i++)
{
a = a * i;
}
for (i=1;i<(fill+1);i++)
{
b = b * i;
}
for (i=1;i<(leftover+1);i++)
{
c = c * i;
}
tote = a/(b*c);
[thePossible setFloatValue:tote];
}
else
{
[thePossible setStringValue :overError];
}
}
@end
[This message has been edited by havannas (edited 05-15-2001).]
[This message has been edited by havannas (edited 05-15-2001).]