This is my code and i do understand the logic but i don't understand the algorithm. About the Parking time coz when i give 1:26 in the time in and 2:20 in time out, i got a negative parking time. here's my code
#include<stdio.h>
void menu(char a);
void getData(int *a, int *b, int *c, int *d);
void dis(int a, int b, int c, int d);
int hrsT(int a, int b);
int minT(int c, int d);
void res(int hr, int min);
int main()
{
int a,b,c,d;
char e;
clrscr();
printf("Type of vehicle: ");
scanf("%c", &e);
menu(e);
getch();
}
void menu(char a)
{
int l,m,n,o;
switch(a)
{
case 'C':
case 'c': clrscr();
printf("\t\tCar\n\n");
getData(&l,&m,&n,&o);
dis(l,m,n,o);
res(hrsT(l,n),minT(m,o));
break;
case 'B':
case 'b': clrscr();
printf("\t\tBus\n\n");
getData(&l,&m,&n,&o);
break;
case 'T':
case 't': clrscr();
printf("\t\tTruck\n\n");
getData(&l,&m,&n,&o);
break;
}
}
void getData(int *a, int *b, int *c, int *d)
{
printf("Hour vehicle entered a lot (0-24)?: ");
scanf("%d", a);
printf("Minute vehicle entered a lot (0-60)?: ");
scanf("%d", b);
printf("Hour vehicle left a lot (0-24)?: ");
scanf("%d", c);
printf("Minute vehicle left a lot (0-60)?: ");
scanf("%d", d);
}
void dis(int a, int b, int c, int d)
{
printf("\n\nTime In\t\t %d : %d", a,b);
printf("\nTime Out\t %d : %d", c,d);
printf("\n\t\t -------");
}
int hrsT(int a, int b)
{
int hrsT;
if(b<a)
hrsT=(a-b)-1;
else
hrsT=b-a;
return hrsT;
}
int minT(int c, int d)
{
int minT;
if(d<c)
minT=(c-d)-60;
else
minT=d-c;
return minT;
}
void res(int hr, int min)
{
int time;
printf("\nParking time\t %d : %d", hr, min);
if(min>0 || min<0)
time=hr+1;
printf("\nRounded total\t %d", time);
}
Could someone clarify this things?