Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

easy question

Posted on 1998-09-29
13
Medium Priority
?
183 Views
Last Modified: 2010-04-01
I need to display double 00 to represent seconds minutes
for a clock program that I am writing
just inserting double 00 is wrong of course
declaring them as a char doesn't work.
thank you
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
  • 4
  • 2
  • 2
  • +5
13 Comments
 
LVL 84

Expert Comment

by:ozo
ID: 1174014
printf("%02d:%02d",minutes,seconds);
0
 
LVL 8

Expert Comment

by:Answers2000
ID: 1174015
BTW ozo's answers assumes minutes & seconds are int variables
0
 

Author Comment

by:strmtrpr
ID: 1174016
I have to display the time using cout.

0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 6

Expert Comment

by:thresher_shark
ID: 1174017
Why must you display the time using cout?  printf would work equally well (I think).  Please tell us more about what you want to do.
0
 

Author Comment

by:strmtrpr
ID: 1174018
I had to write a class that had threee inline functions .
1. to set the clock
2. to increment the clock.
3. to display the time. in standard or milatary . depending on the argument this function received.
I taking a C++ class , I have everything working except for this. we are not supposed to printf
I wish I could use printf I think it would be easier.
any help would be great.

0
 

Expert Comment

by:bbarnette
ID: 1174019
This is what I use to display date or time:

time_t ltime;
struct tm* ldate;

time(&ltime);
ldate = localtime(&ltime);

cout <<ldate->tm_min<<":"<<ldate->tm_sec<<endl;

0
 
LVL 6

Expert Comment

by:thresher_shark
ID: 1174020
If you already have the variables all straightened out, you can just:

cout << minutes << ":" << seconds;

Or perhaps:
cout << hours << minutes << seconds;
0
 
LVL 2

Expert Comment

by:mlev
ID: 1174021
How about this:

char buf[6];
sprintf(buf, "%02d:%02d",minutes,seconds);
cout << buf << endl;

0
 
LVL 2

Expert Comment

by:mlev
ID: 1174022
Btw, I don't know what compiler you're using, but in G++
you can do
cout.form("%02d:%02d",minutes,seconds);

0
 

Author Comment

by:strmtrpr
ID: 1174023
thanks everyone for their help I think I am going to rethink the increment function

0
 
LVL 11

Accepted Solution

by:
alexo earned 40 total points
ID: 1174024
#include <iostream.h> // plain <iostream> on newer compilers
#include <iomanip.h>  // plain <iomanip> on newer compilers

int main()
{
    int hour = 11, min = 2, sec =3;
    cout << setfill('0');
    cout << setw(2) << hour << ':' << setw(2) << min << ':' << setw(2) << sec << endl;
   
    return 0;
}
0
 
LVL 1

Expert Comment

by:Grailman
ID: 1174025
Since a printf is 'compiled' at run-time, how much of an actual performance diffrence is there between printf & cout?
0
 

Author Comment

by:strmtrpr
ID: 1174026
I am taking a c++ Class the teacher wanted us to get use to cout instead of printf
the c++ books I have seen, don't use printf they use cout.
I have had a C class and I am use to the printf,scanf etc  Trying to get use to cout cin  is taking a while.  

by the way .
someone last night commeted that I use under G++.
cout.form("%02d,%02d,%02d",hours,minutes,second);
so I booted into LINUX  2 minutes later I was up and running
thanks for the help.


0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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

This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
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.

722 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