Sep 5, 2011 at 9:41am UTC
the given entry time is 0830
the given exits time is 1300
i'm using turbo c++
i know using normal calculations
i'm supposed to get 4 hours and 30 minutes
but i'm cracking my head up
trying to figure out how to do that
this is my coding so far
void main (void)
{
int entime,extime,total;
int h,m;
char C;
printf("METROPOLITAN PARKING SYSTEM\n");
printf("Enter Code: ");
scanf("%c",&C);
printf("Enter Entry Time: ");
scanf("%d",&entime);
printf("Enter Exits Time: ");
scanf("%d",&extime);
total = extime - entime ;
h = total / 100 ;
m = total % 100 ;
printf("Total Hour: %d hours %d minutes ",h,m);
}
Sep 5, 2011 at 10:10am UTC
This code
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 28 29 30 31 32
#include <cstdio>
int main ()
{
int entime,extime,total;
int h,m;
char C;
printf("METROPOLITAN PARKING SYSTEM\n" );
printf("Enter Code: " );
scanf("%c" ,&C);
printf("Enter Entry Time: " );
scanf("%d" ,&entime);
printf("Enter Exits Time: " );
scanf("%d" ,&extime);
total = extime - entime ;
h = total / 100 ;
m = total % 100 ;
printf("Total Hour: %d hours %d minutes " ,h,m);
return 0;
}
with these inputs:
produces this output:
Total Hour: 4 hours 30 minutes
Using the inputs 0830 and 1300 gives 70 minutes.
This is because your code assumes there are 100 minutes in an hour (i.e. 1300 - 0830 = 470)
Last edited on Sep 5, 2011 at 10:14am UTC
Sep 5, 2011 at 12:09pm UTC
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 28 29
#include <cstdio>
int main ()
{
int entime,extime,total;
char C;
printf("METROPOLITAN PARKING SYSTEM\n" );
printf("Enter Code: " );
scanf("%c" ,&C);
printf("Enter Entry Time: " );
scanf("%d" ,&entime);
printf("Enter Exits Time: " );
scanf("%d" ,&extime);
entime = ((entime / 100) *60) + ( entime % 100);
extime = ((extime / 100) *60) + ( extime % 100);
total = extime - entime ;
printf("Total Hour: %d hours %d minutes " , (total / 60), (total % 60) );
return 0;
}
Last edited on Sep 5, 2011 at 12:12pm UTC
Sep 5, 2011 at 3:20pm UTC
thank you very much
you all are great help
thank you!!!
this is just phase 1 of my programming assignment
i'm so glad i've ask
thank you for replying
THANK YOU !!!!!
please assist me,if i face some more problem.