one other small problem im having, i also need to make a program that subtracts one time from another, it is supposed to display in 24 h format, thing is i cant seem to get 00:00 hours to appear by subtracting two times that are the same ie 10:00 - 10:00 I have managed to get a display of 22:00 hoursso what am i doing wrong?
here is the code
Code:
#include <stdio.h>
#include <conio.h>
void main (void)
{
int hours,hours2=0;
int mins, mins2=0;
clrscr();
printf("Enter the time you reqire (hours) 24-h format: ");
scanf("%d", &hours);
fflush(stdin);
printf("\n");
printf("now enter the minutes: ");
scanf("%d", &mins);
fflush(stdin);
if (hours >23)
hours=0;
if (mins >=60)
{
mins=mins-60;
hours++;
}
printf("the time entered is %2d:%.2d\n", hours, mins);
printf("\n");
printf("Enter the time you wish to be subtracted (hours): ");
scanf("%d", &hours2);
fflush(stdin);
printf("\n");
printf("now enter the minutes: ");
scanf("%d", &mins2);
fflush(stdin);
if ((hours2<hours) && (mins2<mins))
{
hours=hours2-hours;
mins=mins2-mins;
}
else
{
hours=hours-hours2;
mins=mins2-mins;
hours--;
}
if (hours<0)
hours=hours+23;
printf("the time is now %.2d:%.2d", hours, mins);
}