Question

For C Programming: Write a program that reads two times in military format (e.g. 0900, 1730),...

For C Programming:

Write a program that reads two times in military format (e.g. 0900, 1730), and prints the number of hours and minutes between the two times. 
Assume that the hours and minutes of the second time are greater than the first time.
See an example below. User input is underlined (your program does not have to underline the user input).

Please enter the first time: 0900
                             ----
Please enter the second time: 1730
                              ----
8 hours 30 minutes
0 0
Add a comment Improve this question Transcribed image text
Answer #1
#include <stdio.h>

int main() {
    int first, second, hours, minutes;
    printf("Please enter the first time: ");
    scanf("%d", &first);
    printf("Please enter the second time: ");
    scanf("%d", &second);
    if (first > second) {
        hours = (first / 100) - (second / 100);
        minutes = (first % 100) - (second % 100);
        minutes = 24 * 60 - (hours * 60 + minutes);
        hours = minutes / 60;
        minutes %= 60;
    } else {
        hours = (second / 100) - (first / 100);
        minutes = (second % 100) - (first % 100);
    }
    printf("%d hours %d minutes\n", hours, minutes);
    return 0;
}

Add a comment
Know the answer?
Add Answer to:
For C Programming: Write a program that reads two times in military format (e.g. 0900, 1730),...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT