Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

abcdefg12345

macrumors 6502
Original poster
Jul 10, 2013
281
86
Im trying to make a button that calculates the factorial of the number interred into a textfield,

is there a way to do this with Xcode, the ! sign docent work is there some kind of formula i can use to find the factorial of a number using Xcode

thats what i done but its not working


.h
Code:
@property (weak) IBOutlet NSTextField *Field;
- (IBAction)Calculate:(id)sender;

.m
Code:
- (IBAction)Calculate:(id)sender
{
    float result = ([_Field floatValue] * ([_Field floatValue]-1)*[_Field floatValue]);
    [_Field setFloatValue:result];
}
 
Last edited:
is there a way to do this with Xcode, the ! sign docent work is there some kind of formula i can use to find the factorial of a number using Xcode

! is a logical negation operator in C and therefor Obj-C. You need to create a loop that multiplies all values together. Something like;

Code:
result = 1

for i in {1 .. n}
    result = result * i
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.