Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

C++ timer.h header file

Posted on 2003-03-26
9
Medium Priority
?
964 Views
Last Modified: 2008-02-01
Hi,

Could you tell me how the timer.h header file works.  Im currently a beginner in C++ programming and creating a phonebox in C++ for an assignment, and it requires money to be counted down, ive never used the timer.h before so unsure about the code that is required.

Thanks
0
Comment
Question by:Kev_Mc01
  • 3
  • 3
7 Comments
 
LVL 4

Expert Comment

by:n_fortynine
ID: 8213057
There doesn't seem to be a <timer.h> not as I know of. There is one that's called time.h probably that's what you meant? In this case, why would you want to use time.h? What task are you trying to accomplish here?

>> it requires money to be counted down
I'm not clear what you mean here...
0
 

Author Comment

by:Kev_Mc01
ID: 8213117
Sorry its the time.h header file.
Basically the program that i am trying to create is a phonebox.  It asks the user what kind of call they would like to make (long distance or local) and to enter their coinage, for example, 10 p.  It will then ask the user how many 10p they are entering, e.g. 5, it would then calculate 10 mulitplied by 5 to give 50 pence, 50 would be equal to 50 seconds (roughly) for the phone call.  I need to use a time to countdown the 1 p every second, but im unsure how to do this.

Thanks
0
 
LVL 4

Expert Comment

by:n_fortynine
ID: 8213296
how accurate do you want this counting to be? (based on what you're doing it doesn't seem that you have to be *precisely* accurate--unless you're trying to develop a real-time application) do you need to process anything during this duration (each second)? the easiest way to *count* the seconds is to make the system "sleep" for a certain amount of time e.g.

for(count = 50; count; --count)
   sleep(1000);  //1000 miliseconds.

this will effectively pause the system for roughly 50 seconds (or how much longer/shorter you want it to). To use sleep(), include <unistd.h> or if you are using VC++ MFC, use ::sleep(/*milisecs*/). Will this do? =)
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:Kev_Mc01
ID: 8213374
It doesnt have to be precisely accurate, when the time is counting down there is no user input in that time, its just basically to simulate a call so i think what your saying is right.  Is it possible for the program to display each second as its counting down?  So that the user knows when they are nearly out of credit to enter more calls.  I have done a similar program to this in Visual Basic, but like i say im new to C++, thanks for the code.
0
 
LVL 4

Accepted Solution

by:
n_fortynine earned 100 total points
ID: 8213840
yeah all you have to do is to do for example:
for(count = 50; count; --count) {
   sleep(1000);
   if(count % 10 == 0)
      cout << "You have " << count << " seconds left.\n";
}
this will display, say, the remaining seconds every 10 seconds or so... Hope you'll get it.
0
 

Expert Comment

by:CleanupPing
ID: 9446762
Kev_Mc01:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
EXPERTS:
Post your closing recommendations!  No comment means you don't care.
0
 

Author Comment

by:Kev_Mc01
ID: 9505489
Thanks for all the help, the timer was able to function and i ended up recieving a Merit for that assignment, so thanks again :)
0

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When you discover the power of the R programming language, you are going to wonder how you ever lived without it! Learn why the language merits a place in your programming arsenal.
No other job is as rewarding and demanding as building an iPhone app is. It is not really in the hands of the developer for the success of an iPhone app. Many factors operate jointly for every iOS application's success in the market.
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…
Starting up a Project

581 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