I wanted to subtract two time interval. here one time interval is 5hour 30 minute and other is current time.the code is written as follow.
Error report i am getting while run on arduino platform . but this code working fine run on python.
error: invalid operands of types 'double' and 'int' to binary 'operator%'
main()
{
int Time1;
int Time2;
int hour=10;
int minute=5;
int second=13;
int h; int m;
double Ntime;
Time1=(3600*5)+(60*30);
Time2=(3600*hour)+(60*minute)+second;
Ntime=Time2-Time1;
Ntime=((Ntime%60)/100+(Ntime/60));
h=(int)(Ntime);
m=((Ntime-h)*100);
printf("hour after subtraction is : %d hour %d min",h,m)
}
AMPS-N:
I wanted to subtract two time interval. here one time interval is 5hour 30 minute and other is current time.the code is written as follow.
Error report i am getting while run on arduino platform . but this code working fine run on python.
error: invalid operands of types 'double' and 'int' to binary 'operator%'
I have a Rexx program that does the same thing, and it works, so why doesn't it work on an Arduino?
AMPS-N:
I wanted to subtract two time interval. here one time interval is 5hour 30 minute and other is current time.the code is written as follow.
Error report i am getting while run on arduino platform . but this code working fine run on python.
error: invalid operands of types 'double' and 'int' to binary 'operator%'
main()
{
int Time1;
int Time2;
int hour=10;
int minute=5;
int second=13;
int h; int m;
double Ntime;
Time1=(36005)+(6030);
Time2=(3600hour)+(60minute)+second;
Ntime=Time2-Time1;
Ntime=((Ntime%60)/100+(Ntime/60));
h=(int)(Ntime);
m=((Ntime-h)*100);
printf("hour after subtraction is : %d hour %d min",h,m)
}
Modulo (%) only works on integers (int or long) not floating point values. So Ntime%60is invalid because Ntime is a double (why ?)
The code does not compile because of a missing semi-colon nor does it produce any output because it uses printf(). Is this really an Arduino question ?
I have time t1=13:05
t2=5:30
t1 minute=1360+05=785
t2 in minute=560+30=330
t1-t2=455minute
time diff=455/60=7 hour 58 minute
but expected is 7 hour 35 minute
question here how to calibrate above. Yes i have written in C ,then i converting to Arduino IDE just replacing printf to Serial.printf.
Do you understand decimal (base 10) arithmetic?
Do you understand how it differs from sexagesimal (base 60) arithmetic?
0.58 of an hour is not 58 minutes.
converting to Arduino IDE just replacing printf to Serial.printf.