473,394 Members | 1,737 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Call the same function after a particular time repeatedly

Digital Don
Hi,

I want to write a program to simulate a cafetaria in which a customer enters the cafetaria every 10 ~ 50 seconds. So I wanted a function to be called every 10~50 seconds depending on what time is chosen by the random number generator.

I want to know which header file has the function whcih will help me repeat a function call every x seconds. I know there is one in the GLUT library but I want to use a non Graphics header file. So please let me know the header and function which will help me do my implementation.

another question is as follows, I have 2 probabilities i.e. 40% of people choose sandwish counter and 60% choose main. how do I select randomly if a customer should choose sandwich or main counter. Lemme know if anyone got any ideas.


Thank You in advance.

Regards
Digital Don
Sep 11 '07 #1
5 5260
Ganon11
3,652 Expert 2GB
Hey,

Please take the time to look at the Stickies in any area you post in. Had you done so here, you would have seen the thread titled, "DO NOT POST QUESTIONS HERE." Oops! You probably meant to post this in the Forum section; I'll move it there.
Sep 12 '07 #2
gpraghuram
1,275 Expert 1GB
Hi,

I want to write a program to simulate a cafetaria in which a customer enters the cafetaria every 10 ~ 50 seconds. So I wanted a function to be called every 10~50 seconds depending on what time is chosen by the random number generator.

I want to know which header file has the function whcih will help me repeat a function call every x seconds. I know there is one in the GLUT library but I want to use a non Graphics header file. So please let me know the header and function which will help me do my implementation.

another question is as follows, I have 2 probabilities i.e. 40% of people choose sandwish counter and 60% choose main. how do I select randomly if a customer should choose sandwich or main counter. Lemme know if anyone got any ideas.


Thank You in advance.

Regards
Digital Don
Hi,
If you want to schedule your program to run every x seconds then you can use cron-tabin Unix and in windows you can use scheduled-task.

Raghuram
Sep 12 '07 #3
Hi,
If you want to schedule your program to run every x seconds then you can use cron-tabin Unix and in windows you can use scheduled-task.

Raghuram
Is this solution for programming or normal windows task thing...I wanted to know if there is a function in C++ whcih will recall a function every x seconds...

I dont want to run some program in a scheduled fashion...I want to write a C++ program which will simulate a cafetaria in whcih I need to know how to call a function every x second...


Thank You.

Regards,
Digital Don
Sep 12 '07 #4
Suko
6
Hi,

Just use #include <time.h> and use the time function to compare elapsed time.

On the percent q, theres lots ways, e.g get a random number upto 100 then if its <40 its the 40% if its >40 its the 60%

theres many more simpler quicker or better but im tired, its been a long day!
Sep 12 '07 #5
Is this solution for programming or normal windows task thing...I wanted to know if there is a function in C++ whcih will recall a function every x seconds...

I dont want to run some program in a scheduled fashion...I want to write a C++ program which will simulate a cafetaria in whcih I need to know how to call a function every x second...


Thank You.

Regards,
Digital Don
Hi,

The solution offered by Raghuram is to schedule a program to execute on a schedule (e.g. run a script every day at 5:00pm) and will not help you accomplish what you are trying to do.

If you're using Windows, the only way that I know of to call a function repeatedly at a set interval is by using Windows API calls, or a wrapper class to the API calls. You can find such a wrapper class here. I actually just implemented it today, and it works very well.

(Mods: This is a link to a programming blog. Since it's not a competing forum I thought it would be OK to post a link to it. If it's not please let me know).

You can also find a lot of information on timers by searching for "C++ timers" on your favorite search engine.
Sep 12 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Kurt Van Campenhout | last post by:
Hi, I am trying to get/set Terminal server information in the active directory on a windows 2000 domain. Since the ADSI calls for TS don't work until W2K3, I need to do it myself. I'm fairly...
7
by: Steve_Black | last post by:
Hello, I'm toying with the idea of loading a MenuStrip (VB.Net 2005) dynamically based on who is logged into my system. Every user has different security settings and I want to customize the...
46
by: Steven T. Hatton | last post by:
I just read §2.11.3 of D&E, and I have to say, I'm quite puzzled by what it says. http://java.sun.com/docs/books/tutorial/essential/concurrency/syncrgb.html <shrug> -- NOUN:1. Money or...
0
by: Mike S | last post by:
I've seen examples of using the CallWindowProc Windows API function to call functions through their addresses in VB6 -- a clever workaround to emulate C-like function pointer semantics. A...
9
by: Steve Richter | last post by:
in a generic class, can I code the class so that I can call a static method of the generic class T? In the ConvertFrom method of the generic TypeConvert class I want to write, I have a call to...
9
by: CryptiqueGuy | last post by:
Consider the variadic function with the following prototype: int foo(int num,...); Here 'num' specifies the number of arguments, and assume that all the arguments that should be passed to this...
2
by: dolphin | last post by:
What is the different between c++ call convention and c call convention?Can some give some examples?
12
by: aaragon | last post by:
I have this scenario: several arrays for which I have their fixed values at compilation time. Now, at runtime I need to access a specific array depending on an integer but I want to avoid if and...
44
by: Steven D'Aprano | last post by:
I have a class which is not intended to be instantiated. Instead of using the class to creating an instance and then operate on it, I use the class directly, with classmethods. Essentially, the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.