Getting "error: invalid operands of types 'double' and 'const double' to binary 'operator%'

I'm writing a program that gets the current time, I took the example off of the tutorials on this site for getting the current time and now I'm trying to break up the seconds into years then months etc. When I'm compiling I get the error "error: invalid operands of types 'double' and 'const double' to binary 'operator%' and can't figure out how to fix it, does somebody know what I'm doing wrong?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
  /* time example */
#include <stdio.h>      /* printf */
#include <time.h>       /* time_t, struct tm, difftime, time, mktime */
#include <iostream>
using namespace std;
const double SECONDSINAYEAR = 31536000;
int main ()
{
        time_t timer;
        struct tm y2k;
        double seconds;
        double secondsyear;
        double leftoverseconds;
        y2k.tm_hour = 0;   y2k.tm_min = 0; y2k.tm_sec = 0;
        y2k.tm_year = 100; y2k.tm_mon = 0; y2k.tm_mday = 1;

        time(&timer);  /* get current time; same as: timer = time(NULL)  */

        seconds = difftime(timer,mktime(&y2k));
        secondsyear = seconds/SECONDSINAYEAR;
        leftoverseconds = seconds % SECONDSINAYEAR;
        cout << "seconds year: " << secondsyear << endl;
        cout << "lefoverseconds: " << leftoverseconds << endl;

  return 0;
}
binary 'operator%'
if you don't know what this means I'll translate to english: "integers only".
Also I would recommend that you do not store seconds (or any time variable) in double or float as they are less precise than integer.
Oh alright, thanks!
Topic archived. No new replies allowed.