Using time in programs

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: May 2004
Posts: 15
Reputation: dooda man is an unknown quantity at this point 
Solved Threads: 0
dooda man dooda man is offline Offline
Newbie Poster

Using time in programs

 
0
  #1
Jun 11th, 2004
I asked before for a time delay function which is like system ("pause") but depend on time instead of keys , to elaborate i want the program instead if writing " press any key to contiue " i want it to freeze for example for 2 or 3 sec then continue. i got replies which i cant understand, its just codes without explaining the meaning of the function or the input or the output. plz reply me again with more explanation . i really need that facility and i want to understand it.
"NOTE: i am using simple console app with visiual C++ 6 compiler"
thnx
hope u can reply me soon
bye
Reply With Quote Quick reply to this message  
Join Date: Mar 2004
Posts: 28
Reputation: Bleek is an unknown quantity at this point 
Solved Threads: 0
Bleek Bleek is offline Offline
Light Poster

Re: Using time in programs

 
0
  #2
Jun 11th, 2004
yea... it's very useful... here's the code:

#include <iostream>
#include <windows.h>
#include <cstdlib>
using namespace std;

  1. int main()
  2. {
  3. cout << "Hello...";
  4. Sleep(2000);
  5. cout << "World...";
  6. cin.get();
  7.  
  8. return 0;
  9. }//end main function

if you do not have the windows.h header for some odd reason unknown to me, which you have VC++6 so you should, try to run a loop a bunch of times through to give it that effect which windows.h basically does. it just measures your processor speed and does an equation using that... peace...
Reply With Quote Quick reply to this message  
Join Date: May 2004
Posts: 256
Reputation: FireNet will become famous soon enough FireNet will become famous soon enough 
Solved Threads: 6
FireNet's Avatar
FireNet FireNet is offline Offline
Posting Whiz in Training

Re: Using time in programs

 
0
  #3
Jun 12th, 2004
Hey not sleep(2000) bleek, sleep(4) might be a nice number if sleep() is the same for your complier as for mine.I use Borland C++ and sleep() counts in seconds.

There is also delay(int) funtion.It counts in some unit lower than a second.
#include <stdlib.h>
#include <dos.h>

(I dont know which compiler you guys use)
:surprised
See what you can, remember what you need

Fourzon | Earn via Coding
Reply With Quote Quick reply to this message  
Join Date: May 2004
Posts: 15
Reputation: dooda man is an unknown quantity at this point 
Solved Threads: 0
dooda man dooda man is offline Offline
Newbie Poster

Re: Using time in programs

 
0
  #4
Jun 13th, 2004
Originally Posted by Bleek
yea... it's very useful... here's the code:

#include <iostream>
#include <windows.h>
#include <cstdlib>
using namespace std;

  1. int main()
  2. {
  3. cout << "Hello...";
  4. Sleep(2000);
  5. cout << "World...";
  6. cin.get();
  7.  
  8. return 0;
  9. }//end main function

if you do not have the windows.h header for some odd reason unknown to me, which you have VC++6 so you should, try to run a loop a bunch of times through to give it that effect which windows.h basically does. it just measures your processor speed and does an equation using that... peace...
thnx for ur reply
but can u explain more plz .
when i use this code is makes the whole word "hello world" appears after 5 sec apox. i want appear to appear then after 5 sec world continue.
plz explain what is 2000 .
and some1 told me that this function have bad effects on the pc "This is a reply u can see it if u searched after before that post by few ones"
so plz tell me that stuff
and really thnx
bye
Reply With Quote Quick reply to this message  
Join Date: Mar 2004
Posts: 28
Reputation: Bleek is an unknown quantity at this point 
Solved Threads: 0
Bleek Bleek is offline Offline
Light Poster

Re: Using time in programs

 
0
  #5
Jun 14th, 2004
it should work, it works perfectly fine for me... in my dev-cpp compiler it counts with thousands of a second or something so 2000 is 2000 thousandths which makes 2 seconds... *stops and takes a deap breath*

i dont know what you want me to explain further... peace
Reply With Quote Quick reply to this message  
Join Date: Jun 2004
Posts: 4
Reputation: wolfstrike is an unknown quantity at this point 
Solved Threads: 0
wolfstrike wolfstrike is offline Offline
Newbie Poster

Re: Using time in programs

 
0
  #6
Jun 15th, 2004
i have a good one from my book.




#include <iostream.h>
#include <time.h> // my compiler is out dated update as needed




int main()
{
cout << "enter delay time, in seconds : ";
float secs;
cin >> secs;
clock_t delay = secs * CLOCKS_PER_SEC ;
cout << "starting\a\n";
clock_t start = clock();
while (clock() - start < delay );
cout << "done \a\n";
return 0;

}
Reply With Quote Quick reply to this message  
Join Date: Mar 2004
Posts: 28
Reputation: Bleek is an unknown quantity at this point 
Solved Threads: 0
Bleek Bleek is offline Offline
Light Poster

Re: Using time in programs

 
0
  #7
Jun 15th, 2004
yea... i had to use that one time in school because i was programming in a MAC lab and they didnt have windows.h for me to use Sleep() with...
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C++ Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC