# Time converting problem. (24-hour military format to minutes)

This is a discussion on Time converting problem. (24-hour military format to minutes) within the C Programming forums, part of the General Programming Boards category; Greetings, I'm a student who's currently in his first year and first semester in his CScourse and am having some ...

1. ## Time converting problem. (24-hour military format to minutes)

Greetings, I'm a student who's currently in his first year and first semester in his CScourse and am having some issues with this program right here.

Okay, so you have to enter two different times in 24-hour format so the program could calculate the total
amount of time spent and then convert that time into minutes.

i.e. 100(start time) and 300(end time)

here's my shot at it:

Code:
```#include <conio.h>
#include <stdio.h>

void main(){

int start_time;
int end_time;
int semi_time;
double final_time;

printf("Please enter the time you started (in military time): \n");
scanf("%d", &start_time);
printf("Please enter the time you ended (in military time): \n");
scanf("%d", &end_time);

semi_time = end_time - start_time;
final_time = semi_time * 0.60;

printf("The time that you have spent is: %.0f minute(s)\n", final_time);

getch();

}```

Now the problem is, when I enter certain amounts of time, the output comes out
wrong.

When I enter "120" and "200" the output that comes out is "48 minutes", which is obviously incorrect, becauseit should be "40 minutes".

Now, I know I this is the part that I got wrong:

semi_time = end_time - start_time;
final_time = semi_time * 0.60;

But I can't figure out what to do with it to save my life.
Any help would be greatly appreciated. Thanks in advance.

2. You must convert both input values into the same units before the time difference subtraction.
I suggest in most problem to convert the input into the smallest unit; I would guess that would be minutes.

How do you convert "120" into the correct amount of minutes?
Write down the steps.
Convert the steps into C code.

Tim S.

3. Military Time

I think it's easier if you just convert to regular time and then find the difference.

4. Get your first time... 11:17
What minute of the day is it? (How many minutes since midnight?)
What minute of the day is that?

Subtract.

Of course you're going to run into all kinds of complications... like when you pass midnight and the second number is smaller than the first... but that should get you started in the right direction...

5. Originally Posted by whiteflags
Military Time

I think it's easier if you just convert to regular time and then find the difference.
Actually I've always found military time easier for these problems...