Jump to content
  • Advertisement
Sign in to follow this  
markg

help

This topic is 3893 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I was wondering how to make a program that count's to a certin number to pause before counting to the next number. I put in sleep(1000) for pause 1 sec. I keep receiving a message by the compiler saying undeclared identifier.

Share this post


Link to post
Share on other sites
Advertisement
Here's how to do it:

First off all , create a function called "delay".



void Delay(int for_how_long)
{
int counter=0;
while(counter<for_how_long)
{
//wait..
counter+=1;
}
return;
}




In your main(..) , add the following code:


int value=0;
int delay=0;
cout<<"Give me a number!"<<endl;
cin >> value;
cout<<"Set delay (in seconds!. ie : 1,2,3..)!"<<endl;
cin >> delay;
delay *=1000;//seconds to miliseconds
for (int i=0; i<value;i++)//print the numbers
{
cout <<"Number : "<<i<<" , and waiting for : "<<value/1000<<" second(s)!"<<endl;
Delay(delay);//this will cause delay..
}





Thats it !

[Edited by - 3Dgonewild on November 24, 2007 11:03:37 AM]

Share this post


Link to post
Share on other sites
Quote:
Original post by 3Dgonewild
Here's how to do it:

First off all , create a function called "delay".

*** Source Snippet Removed ***

In your main(..) , add the following code:

*** Source Snippet Removed ***

Thats it !


Bad idea. Some compilers could optimise your delay loop away, since it does nothing and has no side effects. Secondly, your code requires a constant which relates only to the development machine. On a faster machine, the loop will end quicker. On a slow machine it will take longer. In any case there is certainly an API call that suspend your program for a while, allowing other programs to run.

Share this post


Link to post
Share on other sites
You never increment 'counter' in your while loop, 3Dgonewild. He'd get stuck in an infinite loop. Not to mention that the using your code and putting Delay(1000) wouldn't run for 1000 millaseconds(one second), it'd run for 1000 increments, which on a good computer would be over in less than 1 millasecond (or at least drastically less than one second).

Unless by '//wait..' you mean to add 'Sleep(1)' or some other function there?

Share this post


Link to post
Share on other sites
@rip-off:

Well , i wrote the delay() function to help him understand what the function does.
In my example , i could just tell him to include windows header , and call sleep() function.
When i started with programming(You helped me a lot btw , so you must remember my stupid questions..lol) , i wanted clear(= code examples)/well explained answers...
Well , my answer wasn't *well explained* or whatever , but i guess he got the message!

Quote:
Original post by Servant of the Lord
You never increment 'counter' in your while loop, 3Dgonewild. He'd get stuck in an infinite loop.

OOps , sorry :)..

Share this post


Link to post
Share on other sites
Quote:
Original post by markg
I was wondering how to make a program that count's to a certin number to pause
before counting to the next number. I put in sleep(1000) for pause 1 sec. I keep receiving a message by the compiler saying undeclared identifier.


Share this post


Link to post
Share on other sites
Quote:
Original post by rip-off
What platform/compiler/language do you use?

Show us your code, if it is short enough.


I am using that microsoft visual c++.net compiler

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!