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.
main()
{
int Time1;
int Time2;
int hour=10;
int minute=5;
int second=13;
int h; int m;
int Ntime;
Time1=(60*5)+(30);
Time2=60*hour+minute;
Ntime=Time2-Time1;
m=(Ntime%60);
Ntime=Ntime/60;
h=(int)(Ntime);
printf("hour after subtraction is : %d hour %d min",h,m)
}
The
%
operator is meant for integer values only. It won't work with adouble
variable. Change your code to:Ntime = (((int)Ntime%60) / 100 + (Ntime / 60));
I have not looked at any logical errors in your program but the error you post is due to the fact that the mod operator i.e. % expects the operand to be integer. So if you modify your code in this way, it should remove the error.
There is too much type casting involved in your code, you should look for a simpler way to do this. Look into the time.h header file, you may find something useful to work with.
change your statement of calculating Ntime to,
you need to type cast to float/double otherwise /100 will result in integer so fractional part will be truncated.