i’m writing some code for getting some values including course
-(void) locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation {
//somecode
NSString *dirString = [[NSString alloc] initWithFormat:@"%d", newLocation.course];
int myInt = [dirString intValue];
if ((myInt >= 0) || (myint < 90)) {course.text =@ "N";}
if ((myInt >= 90) || (myint < 180)) {course.text =@ "E";}
and so on, but i always retrieve the first value, “N”.
where’s my mistake?
Thank’s!
You may want to change the logical OR to logical and (change
||to&&) which will ensure that the value is between 0 and 90, or 90 and 180.Because of the logical OR, the logic also seems a little flawed to me too, perhaps there is something I’m not understanding about the assumptions you’ve made – but if the value is, say, 200, it will pass the first
ifbecause 200 is greater than 0. It’ll then also pass the secondifbecause 200 is greater than 90. They pass because of the logical OR. Only one of the statements (>= 0 OR < 90) has to be true for it to pass.This would be solved by using logical AND instead.