displaying am and pm

Posted on 1998-10-04
Last Modified: 2011-09-20
given this code sgment:
int time,am,pm
hours<12 ?time=am :time=pm;
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.

Question by:strmtrpr
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3

Accepted Solution

thresher_shark earned 50 total points
ID: 1174363
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!

Expert Comment

ID: 1174364
You see, character variables can only hold one letter.  A string can hold as many as you want.

Author Comment

ID: 1174365
Thanks a lot , I have a bad habit of over looking things
Thanks again


Expert Comment

ID: 1174366
Glad I could help!

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

687 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question