I have a time calculation question on C++

Asked 1 weeks ago, Updated 1 weeks ago, 1 views

For example, in c++, int starth, startm, endh, endm; int th, tm, minutes;

printf ("parking fee calculation program\n\n");
printf("Enter borrowing time (hour):");
scanf("%d %d", &starth, &startm);
printf("Enter departure time (hours):");
scanf("%d %d", &endh, &endm);
printf("parking time: %d hours %d minutes (total %d minutes)\n", th, tm, minutes);

How do I write down the actual parking time in order to calculate the time and minutes? Simply set th = (endh-start), tm = (endm-start), and minutes = ((th)*60)+tm The minutes value is calculated, but I don't know how to express the exact time and minute because th increases by 1 and tm increases by - when I put the values of 2:50 and 7:20.


2022-09-20 10:56

1 Answers

Negative numbers themselves are not that difficult. If 'minute' is a negative number, add 60 to it and subtract 1 from the 'time' value. For example, from 2:50 to 7:10, it's counted as 5 hours - 40 minutes, so it's actually 4 hours and 20 minutes. (10 minutes + 4 hours + 10 minutes) or more of elementary school arithmetic will be omitted.

But this is actually a more complicated problem than you think.

And so on, you have to find the general law by arranging the number of annoying (important) cases that you can think of. I hope you can ask the person who gave you the homework more about the conditions and write a good answer.

2022-09-20 10:56

If you have any answers or tips

© 2022 pinfo. All rights reserved.