Simple first Program - Time Alert

Feb 6, 2008 at 6:58pm
I'm trying to create a program that warns me every time my clock is _ _ : _ 9
so every 10 minutes i want to be alerted when my clock has the minutes in the 9 position. Example: When it's
1:39 PM ALERT
10 min later...
1:49 PM ALERT
10 min later...
1:59 PM ALERT
Etc...

Obviously by closing the program it would stop alerting me but otherwise i'd like it to be a loop until i choose to close it unless there is a simple way to stop it without having to close the entire program. something like (to end push 0) and then have something that checks
if n==0 {
break;
}
or something like that.
I've checked out how to retrieve local time and i somewhat understood it but i have no idea how to incorporate it into an alert saying "The time is now XX:X9".
Last edited on Feb 6, 2008 at 8:21pm
Feb 6, 2008 at 9:12pm
This is not a simple program as you describe it, and not good for a first C++ project.

If you use Unix/Linux/*BSD, use a (ana)cron job that runs at :X9. It runs your program directly or from a shell script which only needs to make the alert. You can pass `date` as a command line parameter to your program. In this case you do have to use
 
`date`

so a shell can interpret this as the execution of date(1) instead of the word date.

Windows Scheduled Tasks doesn't support detailed scheduling, but anacron has been ported to Win32 (part of Cygwin).
Feb 6, 2008 at 10:11pm
ugh... I'm not following that 100%.
Look i just want to have a window like an alert box pop up when the time frame is in this position HH:M9 (H=hours)(M=minutes)

If that's really all that complicated to do how would i go about making a script that simply put up an alert window every 10 minutes and was a loop. Thanks
Feb 7, 2008 at 6:29pm
Hmm I've thought it out now and this is probably the most simple way to do this.

Have a window that pops up and alerts me at a certain time. Wouldn't that be a lot easier than writing something that pops up every 10 minutes? Or would this be harder... I'm so confused i just want to learn how to write a program that will send me an alert every 10 minutes.
Feb 8, 2008 at 5:53am
Well, you would probably be better off doing this in a different language other than C++. If you don't know much about the C++ language itself jumping into windows programming (which is what you would need for a pop-up window) would be a bad idea. I can suggest looking into a simple scripting language if you're looking for a quick solution to this time problem. Otherwise you're going to have to start learning the language to get to the point where you can write a program that sits idle until the clock reads a certain time and then pops up a window.

Hope this helps.
Feb 13, 2008 at 2:57pm
Try studying this, and see if it helps get you anywhere. It runs a clock function that delays the program for three seconds.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
// crt_clock.c
// This example prompts for how long
// the program is to run and then continuously
// displays the elapsed time for that period.
//

#include <stdio.h>
#include <stdlib.h>
#include <time.h>

void sleep( clock_t wait );

int main( void )
{
   long    i = 6000000L;
   clock_t start, finish;
   double  duration;

   // Delay for a specified time.
   printf( "Delay for three seconds\n" );
   sleep( (clock_t)3 * CLOCKS_PER_SEC );
   printf( "Done!\n" );

   // Measure the duration of an event.
   printf( "Time to do %ld empty loops is ", i );
   start = clock();
   while( i-- ) 
      ;
   finish = clock();
   duration = (double)(finish - start) / CLOCKS_PER_SEC;
   printf( "%2.1f seconds\n", duration );
}

// Pauses for a specified number of milliseconds.
void sleep( clock_t wait )
{
   clock_t goal;
   goal = wait + clock();
   while( goal > clock() )
      ;
}


This is sample code that came from the Visual C++ help index. I compiled it in Dev-C++, and it ran fine. Hope it helps.
Feb 13, 2008 at 5:57pm
I've decided i'll wait a while untill i try to write this program. I'm going to college in June at ITT and they provide certification work shops in a variety in programming languages. Hopefully then i'll be scripting with the best of you hahah no i know it takes time and this is a bit advanced for a FIRST program lol.

Hmm... Perhaps does anyone know the best site for pretty much hands on learning. There are a lot of sites out there that explain how to learn C++ but i'm looking more for a site that at the same time, will explain in a decent amount of details what they're teaching and question me to do something. Like a website that says ok so you've just read through this chaper or page that contained blah blah blah. Lets see you write a small program that does this and have it give you small hints on the way.

Idk maybe it's pointless to attempt learning that way if i'm going to learn it for free in college anyways, but it'd be nice to start with a lead over everyone else in the class.

And thanks for the type of hint you gave me grezo, i'm sure if i understood a little bit more about c++ i'd be able to figure it out... that's the kind of learning i like when someone doesn't tell you what to do but kind of guides you. Alright well thanks -
Topic archived. No new replies allowed.