The Time Machine-Time Machine calculation difference value (within 24 hours): enter hours, minutes, 1 stands for am, 0 stands for PM.
// The Time Machine-Time Machine calculation difference value (within 24 hours) # include <iostream> int computedifference (INT starthours, int startminutes, bool startisam, int endhours, int endminutes, bool endisam); int main () {using namespace STD; int starthours, startminutes, endhours, endminutes; bool startisam, endisam; int total_minutes; cout <"Please inout the start time (starthours, startminutes, startisam (1: am; 0: PM): \ n"; CIN> starthours> Star Tminutes> startisam; cout <"Please inout the end time (endhours, endminutes, endisam (1: am; 0: PM): \ n "; cin> endhours> endminutes> endisam; total_minutes = computedifference (starthours, startminutes, startisam, endhours, endminutes, endisam ); cout <"The difference value of the two time is" <total_minutes <"minutes! "<Endl; return 0;} int computedifference (INT starthours, int startminutes, bool startisam, int endhours, int endminutes, bool endisam) {using namespace STD; int total_minutes; if (true = startisam & false = endisam) {If (startminutes <= endminutes) total_minutes = (endhours-starthours) * 60 + (endminutes-startminutes ); else total_minutes = (endhours-1-starthours) * 60 + (endminutes + 60-startminutes);} else if (true = startisam & True = endisam) {If (starthours <endhours) {If (startminutes <= endminutes) total_minutes = (endhours-starthours) * 60 + (endminutes-startminutes ); else total_minutes = (endhours-1-starthours) * 60 + (endminutes + 60-startminutes);} else if (starthours> endhours) {If (startminutes> = endminutes) total_minutes = 24*60-(starthours-endhours) * 60 + (startminutes-endminutes); else total_minutes = 24*60-(starthours-1-endhours) * 60 + (startminutes + 60-endminutes);} else if (starthours = endhours) {If (startminutes <= endminutes) total_minutes = (endhours-starthours) * 60 + (endminutes-startminutes); else total_minutes = 24*60-(startminutes-endminutes);} else if (false = startisam & amp; false = endisam) {If (starthours <endhours) {If (startminutes <= endminutes) total_minutes = (endhours-starthours) * 60 + (endminutes-startminutes ); else total_minutes = (endhours-1-starthours) * 60 + (endminutes + 60-startminutes);} else if (starthours> endhours) {If (startminutes> = endminutes) total_minutes = 24*60-(starthours-endhours) * 60-(startminutes-endminutes); else total_minutes = 24*60-(starthours-1-endhours) * 60-(startminutes + 60-endminutes);} else if (starthours = endhours) {If (startminutes <= endminutes) total_minutes = (endhours-starthours) * 60 + (endminutes-startminutes); else total_minutes = 24*60-(startminutes-endminutes);} else if (false = startisam & True = endisam) {If (startminutes> = endminutes) total_minutes = 24*60-(starthours-endhours) * 60-(startminutes-endminutes ); else total_minutes = 24*60-(starthours-1-endhours) * 60-(startminutes + 60-endminutes);} return total_minutes ;}
Result:
Please inout the start time (startHours,startMinutes,startIsAM(1:AM;0:PM)):11 59 1Please inout the end time (endHours,endMinutes,endIsAM(1:AM;0:PM)):12 01 0The difference value of the two time is 2 minutes!Please inout the start time (startHours,startMinutes,startIsAM(1:AM;0:PM)):11 59 1Please inout the end time (endHours,endMinutes,endIsAM(1:AM;0:PM)):11 58 1The difference value of the two time is 1439 minutes!
The Time Machine-difference calculated by the time machine (within 24 hours)