Solved

displaying am and pm

Posted on 1998-10-04
4
286 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
  • 3
4 Comments
 
LVL 6

Accepted Solution

by:
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!
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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

707 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now