1,105,534 Community Members

C++ program to convert military time to standard time

Member Avatar
sameerge
Newbie Poster
2 posts since Jan 2012
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

hi guys

Can anyone write a C++ program for me which convert military time to standard time without using return function. write a simple program which start from

#include<iostream.h>
#include<coino.h>
void main()
{
.
.
.
.
.
.
.
getch();
}

Member Avatar
sfuo
Master Poster
713 posts since Jul 2009
Reputation Points: 109 [?]
Q&As Helped to Solve: 111 [?]
Skill Endorsements: 0 [?]
 
0
 

Try starting with this

#include <iostream>
using namespace std;

void MyFunction()
{
	//does something
}


int main()
{
	MyFunction();

	return 0;
}
Member Avatar
LRRR
Junior Poster in Training
55 posts since Dec 2011
Reputation Points: 9 [?]
Q&As Helped to Solve: 15 [?]
Skill Endorsements: 0 [?]
 
0
 

Come on, think. :) This is very easy. How do we convert from 24h notation to 12? When someone says it's 23:00 you know, it is 11:00 pm, or 22:00 is 10:00 pm 21:00 is 9, 20:00 is 8.

24 -> 0
23 -> 11
22 -> 10
21 -> 9
20 -> 8
19 -> 7
18 -> 6

Look at the difference between 23 and 11, 22 and 10 and so on. It's always 12. You only need to subtract 12. It is slightly more elegant to do it with the modulo operator.

22 % 12 = 10
21 % 12 = 9
24 % 12 = 0;

Member Avatar
thines01
Postaholic
2,420 posts since Oct 2009
Reputation Points: 389 [?]
Q&As Helped to Solve: 413 [?]
Skill Endorsements: 10 [?]
Team Colleague
Featured
 
0
 

Will your input be a time_t or some other time structure?
Will it be a string that is input by the user?

Member Avatar
Narue
Bad Cop
12,139 posts since Sep 2004
Reputation Points: 5,693 [?]
Q&As Helped to Solve: 1,537 [?]
Skill Endorsements: 81 [?]
Team Colleague
 
0
 

OP clearly has no intention of doing any work, which means this violates our homework rule. Thread closed.

You
This article has been dead for over three months: Start a new discussion instead
Post:
Start New Discussion
View similar articles that have also been tagged: