Question
C++ You have a time machine that can go forward in time (no reverse time-travel yet). The machine is configured to jump ahead in minutes.
C++
You have a time machine that can go forward in time (no reverse time-travel yet). The machine is configured to jump ahead in minutes.
The time-traveler will enter a start time and an end time and calculate the difference in minutes between them. The end time will always be within 24 hours (1439 minutes max travel time) of the start time. Use military notation for both the start and end times (e.g., 0000 for midnight and 2359 for one minute before midnight).
TIME INPUT and EDITS
No time can have more than 59 minutese.g. 1159 is a good time 1160 is not. To achieve this edit use the mod operator: if (userTime % 100 is greater than or equal to 60 )) then the time is invalid. Alsono time can be negative.
If the user enters an invalid time then loop with an error message until a valid time is entered.
Remember the user must enter 2 times. Use a function and call it twiceonce for a valid start time and once for a valid end time.
CALCULATIONS
Write a function that takes as arguments a start time and an end time using military notation. The function should return the total minutes traveled as an integer. You must convert the times to minutes using the division and mod operators.
if startTime is less than end time then //all travel is done in the same day 1. startMinutes = (startTime / 100 * 60) + startTime % 100; 2. endMinutes = (endTime / 100 * 60) + endTime % 100; 3. totalMinutes = endMinutes startMinutes else //travel takes place covering 2 days 1. minutesBeforeMid = (startTime / 100 * 60) + startTime % 100; 2. startMinutes = totalMinutesInADay minutesBeforeMid. 3. endMinutes = (endTime / 100 * 60) + endTime % 100 4. totalMinutes = endMinutes + startMinutes
TESTING
In the main method invoke your functions and then display the total minutes traveled by the user. Use good programming style and user interaction as covered in lectures.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started