• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 298
  • 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

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

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