I am trying to simply have a segment when selected pick a factor and use it in a formula. The problem i am having is converting the factor a (float) into a value a (double) and show this on the display. What am I doing wrong here? Seems like an easy fix but I’ve tried a lot of things to no avail.
.h
NSInteger segPicked, var1, var2;
.m
var1 = 1100;
var2 = 2.5;
- (void) pickOne:(id)sender { // Selector for twosegment controller
if (checkCondition == properCondition) {
segUnit.text = [twoSegments titleForSegmentAtIndex: [SixSegments selectedSegmentIndex]];
segPicked = [twoSegments selectedSegmentIndex];
float factor = 0;
if (segPicked == 0 ) {
factor = 0.28;
} else if (segPicked == 1 ) {
factor = 0.16;
}
double value = (factor*(var1/var2)); <--- It crashes here..
Result.text = [NSString stringWithFormat:@"Segment with = ", value];
}
}
check that var2 must be != 0
and:
should be:
EDIT:
it all works good to me, no crashes, are you sure it crashes at that point?
just a consideration:
var2 = 2.5;
var2 is: 2 (it’s an integer)