Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

displaying am and pm

Posted on 1998-10-04
4
Medium Priority
?
297 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

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…
IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
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 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.
Suggested Courses

597 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