• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 301
  • Last Modified:

displaying am and pm

given this code sgment:
int time,am,pm
hours<12 ?time=am :time=pm;
cout<<hours<<mins<<sec<<time;
this is just a code segment from a program that I wrote.
how can I display the am or pm with cout.
I tried declaring them as char:
char time,am,pm;
hours<12 ?time='am':time='pm';
but all I get is is the a or p.
please help.

0
strmtrpr
Asked:
strmtrpr
  • 3
1 Solution
 
thresher_sharkCommented:
Create a string, such as this:
char time[3];

hours<12 ?strcpy (time,"am"):strcpy (time,"pm");

Then cout the time variable just like you are now.

If you have any further questions, please feel free to ask!
0
 
thresher_sharkCommented:
You see, character variables can only hold one letter.  A string can hold as many as you want.
0
 
strmtrprAuthor Commented:
Thanks a lot , I have a bad habit of over looking things
Thanks again

0
 
thresher_sharkCommented:
Glad I could help!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now