GIDForums  

Go Back   GIDForums > Computer Programming Forums > C++ Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 24-Jan-2009, 13:19
sandra sandra is offline
New Member
 
Join Date: Jan 2009
Posts: 2
sandra is an unknown quantity at this point

C++ and time


Hi
please i want help from you, my question is:

How I can pause an execution of program for a few minutes depends on user inter key ,in my program i use time to calculate position of person who is falling from the plane ,I use openGl with C++?
I am trying sleep() , System("PAUSE") , and i hadn't useful from any ones.
  #2  
Old 24-Jan-2009, 20:13
nostaque nostaque is offline
New Member
 
Join Date: Oct 2008
Posts: 19
nostaque will become famous soon enough

Re: C++ and time


This works for me. Hope it helps.


CPP / C++ / C Code:
#include <stdio.h>
#include <iostream>
#include <windows.h>
using namespace std;

int main()
{
    int t;
    cout << "Enter time to pause in second: ";
    cin >> t;
    Sleep(t* 1000);
    cout << "End of time\n";
return 0;
}
  #3  
Old 25-Jan-2009, 10:25
sandra sandra is offline
New Member
 
Join Date: Jan 2009
Posts: 2
sandra is an unknown quantity at this point

Re: C++ and time


Quote:
Originally Posted by nostaque
This works for me. Hope it helps.


CPP / C++ / C Code:
#include <stdio.h>
#include <iostream>
#include <windows.h>
using namespace std;

int main()
{
    int t;
    cout << "Enter time to pause in second: ";
    cin >> t;
    Sleep(t* 1000);
    cout << "End of time\n";
return 0;
}

thank you for replay ..
my problem not with pause execution exactly i take time from computer with GetTickCount() to calculate the position then when i want to pause execution , the time didn't pause and when i resume execution the time take wrong value ,then sleep () doesn't work .
  #4  
Old 29-Jan-2009, 07:50
Blake's Avatar
Blake Blake is offline
Member
 
Join Date: Nov 2005
Posts: 255
Blake is a jewel in the roughBlake is a jewel in the rough

Re: C++ and time


Use a variable to keep track of the total time that the system is paused. Then subtract that time from the time returned by getTickCount(). Example:

CPP / C++ / C Code:

int pauseTime = 0;

int getTime()
{
	return GetTickCount() - pauseTime;
}

int main(int argc, char * argv [])
{
	int t = GetTickCount();
	while (true)
	{
		int pauseStart = GetTickCount();
		cin.get();
		pauseTime += GetTickCount() - pauseStart;
	}
}

The getTime() function will give you the time minus the time spent paused.

On a side note (since you're using OpenGL), if you're using GLUT, you can use glutGet(GLUT_ELAPSED_TIME); to get the elapsed time since the last call to glutInit(). Then you don't need to include windows.h, which is good if you're aiming for platform independence.
__________________
www.blake-foster.com
  #5  
Old 29-Jan-2009, 12:08
nowocien nowocien is offline
Awaiting Email Confirmation
 
Join Date: Nov 2008
Posts: 30
nowocien is an unknown quantity at this point

Re: C++ and time


man your sharp Blake.. care to tell us or just me about some of the programming projects that are NOT listed on your website??

Dan
  #6  
Old 29-Jan-2009, 22:04
Blake's Avatar
Blake Blake is offline
Member
 
Join Date: Nov 2005
Posts: 255
Blake is a jewel in the roughBlake is a jewel in the rough

Re: C++ and time


Thanks! I don't have this on my website yet.
__________________
www.blake-foster.com
 
 

Recent GIDBlogOnce again, no time for hobbies by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
BryanSoft.Com Free Cpanel Hosting And Resellers One Time Posting!!! rewer Free Web Hosting 0 22-Oct-2008 20:56
Asynchronous transfer question crystalattice Miscellaneous Programming Forum 2 24-Jan-2007 21:39
constructors/classes mapes479 C++ Forum 3 19-Nov-2006 18:34
Fortran problem... Justin Fox Miscellaneous Programming Forum 6 24-Oct-2006 16:30
[CONTEST?]Data Structure Test dsmith C Programming Language 2 06-Jun-2004 16:13

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 19:20.


vBulletin, Copyright © 2000 - 2009, Jelsoft Enterprises Ltd.