GIDForums  

Go Back   GIDForums > Computer Programming Forums > C++ Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 16-Feb-2009, 10:04
genesaika genesaika is offline
Awaiting Email Confirmation
 
Join Date: Apr 2008
Posts: 80
genesaika is on a distinguished road

Compare today's date with date last run


I am working on a project and I want it to be in real time.

It is a restuarant program that lets you buy your meal. I am to have a specials menu that changes, but I want this to change in real time.

So what I would like is to have some function to have the previous date run saved to compare it to the new date run.

something like:

CPP / C++ / C Code:
if (__PREVIOUS_DATE__ != __DATE__){
__PREVIOUS_DATE__ = __DATE__ ;
special = rand();
}
else if (__PREVIOUS_DATE__ == __DATE__){
special = special ;
}


Regards,
Gene Saika
  #2  
Old 16-Feb-2009, 12:27
ocicat ocicat is offline
Regular Member
 
Join Date: May 2008
Posts: 580
ocicat is a jewel in the roughocicat is a jewel in the rough

Re: compare today's date with date last run


Quote:
Originally Posted by genesaika
...but I want this to change in real time.
The code posted simply compares the current state of a variable over what it was previously. This is not necessarily an example of real-time processing.
  • If the application has been running continuously, simply save the time the last menu was displayed & compare to the current time.
  • If the application potentially has been terminated, simply save the time to disk, & read it the next time the application is invoked.
  #3  
Old 16-Feb-2009, 12:57
L7Sqr L7Sqr is offline
Member
 
Join Date: Jul 2005
Location: constant limbo
Posts: 234
L7Sqr is a jewel in the roughL7Sqr is a jewel in the rough

Re: compare today's date with date last run


It looks like you are trying to use macros to determine the date of execution (realize that __DATE__ is a macro). These macros are expanded at compile time and thus would require a daily compile to ensure that they are current. Furthermore, you can not assign to a macro (well, you can depending on how you define it but that could be considered bad practice).
What would likely be the best solution for you would be to store a variable somewhere with the last date (get it however your system allows). Each time you want to check compare the current date (again, by whatever means your system provides) with that variable.
There are standard utilities to accomplish these actions on any well-known system.
__________________
My personal site: Utilities for text processing, debugging, testing and plotting
  #4  
Old 16-Feb-2009, 22:03
genesaika genesaika is offline
Awaiting Email Confirmation
 
Join Date: Apr 2008
Posts: 80
genesaika is on a distinguished road

Re: Compare today's date with date last run


I know I can save the date to a file and open that file everytime the program is run, but would there be another option? I am trying to do this without too many extra files.
  #5  
Old 16-Feb-2009, 23:09
ocicat ocicat is offline
Regular Member
 
Join Date: May 2008
Posts: 580
ocicat is a jewel in the roughocicat is a jewel in the rough

Re: Compare today's date with date last run


Quote:
Originally Posted by genesaika
I know I can save the date to a file and open that file everytime the program is run, but would there be another option?
The basic problem is that you want to refer to retained data. If the data is saved in the process space, it will go away when the application terminates. If the data still needs to be referred to at the next invocation, then it will need to be retrieved from somewhere else -- & the obvious choice is from a file.
Quote:
I am trying to do this without too many extra files.
How many is too many? Assuming you have thought through the problem, & can rationalize all decisions made, then whatever is required is necessary.

If your comments revolves around data saved in multiple files, then another alternative is combining them.
  #6  
Old 16-Feb-2009, 23:56
genesaika genesaika is offline
Awaiting Email Confirmation
 
Join Date: Apr 2008
Posts: 80
genesaika is on a distinguished road

Re: Compare today's date with date last run


For now two files might be too many.

So if there isn't another way then I will have to just save the file, but I'd rather another way.

Yes I know that anything I save to a local varible would be erased and that is why I mentioned the __DATE__ thing.

If doign this without saving to a file is not possible then I will, of course, just save to a file.
  #7  
Old 17-Feb-2009, 07:47
L7Sqr L7Sqr is offline
Member
 
Join Date: Jul 2005
Location: constant limbo
Posts: 234
L7Sqr is a jewel in the roughL7Sqr is a jewel in the rough

Re: Compare today's date with date last run


If you have multiple values to store there is no reason you cant store them all in a single file, in fact that is how some databases work.
The fact is when your program ends its memory is erased (not really, just reassigned) to make room for some other process. If you need any part of that memory before it is gone you need store it to some place persistent. This can be a database, flat file, removable media, and so on - each with a varying level of difficulty in execution.
Your other option, as I mentioned before, is to just keep your program running and use a variable within the program to track the current value.
This is what program design is all about; what fits best for your situation can only be decided by you.
__________________
My personal site: Utilities for text processing, debugging, testing and plotting
  #8  
Old 17-Feb-2009, 16:18
ocicat ocicat is offline
Regular Member
 
Join Date: May 2008
Posts: 580
ocicat is a jewel in the roughocicat is a jewel in the rough

Re: Compare today's date with date last run


Quote:
Originally Posted by genesaika
So if there isn't another way then I will have to just save the file, but I'd rather another way.
There are only so many ways to deal with persistence.

If you are dealing with Windows, you could write the value into the registry, but this is also an advanced subject which I recommend you avoid. It would also tie your solution to a specific operating system.

As stated before, I find it hard to believe that your instructor wants such bells & whistles.
 
 

Recent GIDBlogOnce again, no time for hobbies by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Write the declaration for a Date object Sosy C++ Forum 6 26-Oct-2007 10:21
date of Yesterday ctrohaya MySQL / PHP Forum 6 29-Nov-2006 03:37
Date problem coolio2005 Java Forum 1 21-Mar-2006 08:07
Limit combo box and date time picker choice according to database created in folder shinyhui C++ Forum 0 22-Feb-2005 21:16
Limit combo box and date time picker choice according to database created in folder shinyhui MS Visual C++ / MFC Forum 0 22-Feb-2005 03:13

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 14:02.


vBulletin, Copyright © 2000 - 2009, Jelsoft Enterprises Ltd.