?
Solved

displaying am and pm

Posted on 1998-10-04
4
Medium Priority
?
295 Views
Last Modified: 2011-09-20
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
Comment
Question by:strmtrpr
[X]
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
4 Comments
 
LVL 6

Accepted Solution

by:
thresher_shark earned 200 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!
0
 
LVL 6

Expert Comment

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

Author Comment

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

0
 
LVL 6

Expert Comment

by:thresher_shark
ID: 1174366
Glad I could help!
0

Featured Post

New benefit for Premium Members - Upgrade now!

Ready to get started with anonymous questions today? It's easy! Learn more.

Question has a verified solution.

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

In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.
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.
Suggested Courses

752 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