?
Solved

C++ timer.h header file

Posted on 2003-03-26
9
Medium Priority
?
960 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
9 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

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

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
What do responsible coders do? They don't take detrimental shortcuts. They do take reasonable security precautions, create important automation, implement sufficient logging, fix things they break, and care about users.
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…
Six Sigma Control Plans

764 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