Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

XCode error "invalid operands to binary expression"

I have an NSTimeInterval that is stored as a double. I would like to get the amount of minutes that are inide of the second value using the % operator.

int remainingSeconds = scratch % 60;

The error said "invalid operands to binary expression" point at % Help please.

like image 237
Piyo Avatar asked Jun 26 '12 07:06

Piyo


1 Answers

modulus is used on integers, so for your code to work do the following

int remainingSeconds = (int)scratch % 60;

To use modulus on floats use fmod

int remainingSeconds = fmod(scratch, 60);

check answer here How to make a modulo operation in objective-c / cocoa touch?

like image 54
Omar Abdelhafith Avatar answered Nov 01 '22 11:11

Omar Abdelhafith