1,105,546 Community Members

programming a program?

Member Avatar
JonaRab
Newbie Poster
1 post since Jan 2011
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

hey everybody
can anyone helps me, please?
i must program a projekt but i don´t know how i do it.
the projekt:
Write a program to convert from 12-hour time format to 24-hour time format. The 12-
hour format has the form hours:minutes followed by either A, P, AM, or PM (either lower
case or upper case but not mixed). One white space is allowed but not required between
the numerical time and the AM/PM indicator. The 24-hour format must be printed with
leading zeros, to ensure that a 24-hour time always consists of four digits. The output
line is followed by a new-line character.

Member Avatar
Ancient Dragon
Achieved Level 70
27,680 posts since Aug 2005
Reputation Points: 5,234 [?]
Q&As Helped to Solve: 3,041 [?]
Skill Endorsements: 115 [?]
Team Colleague
Featured
Sponsor
 
0
 

What part of the instructions do you not understand? Post what you have attempted to do so far.

Member Avatar
wolfson109
Newbie Poster
1 post since Jan 2011
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

I'm guessing that the user provides the time to be converted? If you store the hours and minutes separately in the variables

int hours, mins;

then you can operate on the hours on their own (since that is all you should need to do in order to convert from 12hr to 24hr). The time of day (am/pm) can be stored as a string of length 2

char day[2];

Then let the user input the time to be converted with the scanf statement

scanf("%d:%d %s",&hours,&mins,&day);

You can use the

strcmp()

function to determine the value of the string in

day[]

(make sure you include the string library), and from that you can operate on the value of

hours

accordingly.
Finally, output the converted time with

printf("%d:%d\n",hours,mins);
You
This article has been dead for over three months: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article