C Board  

Go Back   C Board > General Programming Boards > C Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 02-09-2010, 06:58 AM   #1
Registered User
 
Join Date: Feb 2010
Posts: 2
Exclamation Urgent help please

OK I have a program due in tomorrow and I need to calculate the number of days that have passed since the first day of the year. Can anyone PLEASE help me with the code for this??

Please help as soon as possible, it will be greatly appreciated.
watsee is offline   Reply With Quote
Old 02-09-2010, 07:29 AM   #2
Registered User
 
Join Date: Aug 2006
Posts: 94
1) Get Calender.
2) Find Today.
3) Count Backwards.
4) ???
5) Profit!
rdrast is offline   Reply With Quote
Old 02-09-2010, 07:51 AM   #3
Registered User
 
Join Date: Feb 2010
Posts: 2
OK I half expected a reply like that, come on man please. Its not even for me its for my girlfriend, maaaaajor brownie points if I get this working for her. So come on please someone out there must be able to help me properly.
watsee is offline   Reply With Quote
Old 02-09-2010, 07:56 AM   #4
C++ Witch
 
laserlight's Avatar
 
Join Date: Oct 2003
Location: Singapore
Posts: 12,459
That makes it even worse, methinks

Anyway, one idea is to compute the number of days that have gone by in the previous months of the year, and then add the number of days that have gone by in the current month.
__________________
C + C++ Compiler: MinGW port of GCC
Build + Version Control System: SCons + Bazaar

Look up a C/C++ Reference and learn How To Ask Questions The Smart Way
laserlight is offline   Reply With Quote
Old 02-09-2010, 11:33 AM   #5
Mysterious C++ User
 
Elysia's Avatar
 
Join Date: Oct 2007
Posts: 16,078
Well then, do you have any working code or logic for this? If not, then get started with the logic.
Otherwise, post your current attempt and ask specific questions about what you don't understand.
Furthermore, I would refrain from using "urgent" and "help" in the title. Members will reply at their own pace, when and if they can, regardless if you put in urgent or not. And help isn't very specific.
Such titles ever deter some members.
__________________
Using: Microsoft Windows™ 7 Professional (x64), Microsoft Visual Studio™ 2010 Ultimate, C++0x
"Thanks Elysia. You're a programming master! How the hell do you know every thing?"
"Thanks for all your help. It's obvious yall really know what you're talking about when it comes to OOP/C++ stuff."
Quoted... at least once.
Quote:
Originally Posted by cpjust
If C++ is 2 steps forward from C, then I'd say Java is 1 step forward and 2 steps back.
Elysia is offline   Reply With Quote
Old 02-09-2010, 11:39 AM   #6
dat is, vast staat
 
MK27's Avatar
 
Join Date: Jul 2008
Location: SE Queens
Posts: 6,612
Quote:
Originally Posted by watsee View Post
OK I have a program due in tomorrow and I need to calculate the number of days that have passed since the first day of the year. Can anyone PLEASE help me
Forty!
__________________
C programming resources:
GNU C Function and Macro Index -- glibc reference manual
The C Book -- nice online learner guide
Current ISO draft standard
CCAN -- new CPAN like open source library repository
GDB tutorial #1 -- gnu debugger tutorials -- GDB tutorial #2
cpwiki -- our wiki on sourceforge
MK27 is offline   Reply With Quote
Old 02-09-2010, 11:41 AM   #7
Mysterious C++ User
 
Elysia's Avatar
 
Join Date: Oct 2007
Posts: 16,078
...Uh, right.
__________________
Using: Microsoft Windows™ 7 Professional (x64), Microsoft Visual Studio™ 2010 Ultimate, C++0x
"Thanks Elysia. You're a programming master! How the hell do you know every thing?"
"Thanks for all your help. It's obvious yall really know what you're talking about when it comes to OOP/C++ stuff."
Quoted... at least once.
Quote:
Originally Posted by cpjust
If C++ is 2 steps forward from C, then I'd say Java is 1 step forward and 2 steps back.
Elysia is offline   Reply With Quote
Old 02-09-2010, 11:43 AM   #8
Registered User
 
jeffcobb's Avatar
 
Join Date: Dec 2009
Location: Henderson, NV
Posts: 887
Quote:
Originally Posted by laserlight View Post
That makes it even worse, methinks

Anyway, one idea is to compute the number of days that have gone by in the previous months of the year, and then add the number of days that have gone by in the current month.
Maybe the long way around the block but could conceivably result in shorter code is to get a Gregorian to Julian date converter fn from snippets.org, then call it twice, once with current date and once with 01012010 and subtract...
__________________
C/C++ Environment: GNU CC/Emacs
Make system: CMake
Debuggers: Valgrind/GDB
jeffcobb is offline   Reply With Quote
Old 02-09-2010, 11:44 AM   #9
Registered User
 
jeffcobb's Avatar
 
Join Date: Dec 2009
Location: Henderson, NV
Posts: 887
Quote:
Originally Posted by MK27 View Post
Forty!
Dang it! I thought the answer was *always* 42!!!!!
__________________
C/C++ Environment: GNU CC/Emacs
Make system: CMake
Debuggers: Valgrind/GDB
jeffcobb is offline   Reply With Quote
Old 02-09-2010, 11:46 AM   #10
dat is, vast staat
 
MK27's Avatar
 
Join Date: Jul 2008
Location: SE Queens
Posts: 6,612
I'd figure out the "seconds since the epoch" for 1/1/10 and then use difftime(). There are 3600 seconds in a day.

For further help I think the OP needs to include a pic of the girlfriend.

Quote:
Originally Posted by jeffcobb View Post
Dang it! I thought the answer was *always* 42!!!!!
Only on Thursday.
__________________
C programming resources:
GNU C Function and Macro Index -- glibc reference manual
The C Book -- nice online learner guide
Current ISO draft standard
CCAN -- new CPAN like open source library repository
GDB tutorial #1 -- gnu debugger tutorials -- GDB tutorial #2
cpwiki -- our wiki on sourceforge
MK27 is offline   Reply With Quote
Old 02-09-2010, 11:50 AM   #11
C++ Witch
 
laserlight's Avatar
 
Join Date: Oct 2003
Location: Singapore
Posts: 12,459
Quote:
Originally Posted by MK27
Only on Thursday.
If the girlfriend submits the homework tomorrow (today?), it will probably get marked on Thursday, which is just right
__________________
C + C++ Compiler: MinGW port of GCC
Build + Version Control System: SCons + Bazaar

Look up a C/C++ Reference and learn How To Ask Questions The Smart Way
laserlight is offline   Reply With Quote
Old 02-09-2010, 12:18 PM   #12
Registered User
 
jeffcobb's Avatar
 
Join Date: Dec 2009
Location: Henderson, NV
Posts: 887
Programmers can be such smart@sses

Its why I love this gig...
__________________
C/C++ Environment: GNU CC/Emacs
Make system: CMake
Debuggers: Valgrind/GDB
jeffcobb is offline   Reply With Quote
Old 02-09-2010, 12:29 PM   #13
Registered User
 
jeffcobb's Avatar
 
Join Date: Dec 2009
Location: Henderson, NV
Posts: 887
Quote:
Originally Posted by laserlight View Post
If the girlfriend submits the homework tomorrow (today?), it will probably get marked on Thursday, which is just right
Note one line of code yet either. Lemme fix that.

So if he/she turned it in on Thursday:
Code:
#include <stdio.h>
#include <string.h>

int main(int argc, char*argv[])
{
     int nRC = 0;
     char today[20];
     memset(today, 0, 20);
     // get the command line of day
     if(argc > 1)
     {
           strncpy(today, argv[1], 20);
     }

     if( strcmp(today, 'thursday')==0)
     {
           printf("42!\n");
     }
     else
     {
           printf("Error in computation or input. Try again.\n");
           // tell calling system that we are MASSIVE FAIL
           nRC = -1;
     }
     return nRC;
}
There. That way if the app is called like so:
./myapp thursday
the correct answer will indeed pop out...
__________________
C/C++ Environment: GNU CC/Emacs
Make system: CMake
Debuggers: Valgrind/GDB
jeffcobb is offline   Reply With Quote
Old 02-09-2010, 12:34 PM   #14
C++ Witch
 
laserlight's Avatar
 
Join Date: Oct 2003
Location: Singapore
Posts: 12,459
At a glance, 'thursday' should be "thursday".
__________________
C + C++ Compiler: MinGW port of GCC
Build + Version Control System: SCons + Bazaar

Look up a C/C++ Reference and learn How To Ask Questions The Smart Way
laserlight is offline   Reply With Quote
Old 02-09-2010, 12:44 PM   #15
Registered User
 
jeffcobb's Avatar
 
Join Date: Dec 2009
Location: Henderson, NV
Posts: 887
Quote:
Originally Posted by laserlight View Post
At a glance, 'thursday' should be "thursday".
Sorry was just doing some Python....my mistake!

You know, all joking aside, that can be one of the tricky things about constantly living with multiple languages with similar but not exact syntactical styles....and the single/double quote problem is only one. Like going from Object PASCAL to C++ I get wanting to do things like:

Code:
with <someobject> do:
      foo()

// instead of 
<someobject>.foo();
__________________
C/C++ Environment: GNU CC/Emacs
Make system: CMake
Debuggers: Valgrind/GDB

Last edited by jeffcobb; 02-09-2010 at 12:47 PM.
jeffcobb is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Urgent Help Needed In Writing Algorithm!! Vikramnb C++ Programming 1 01-09-2009 12:46 PM
BitWise Newbie - Needs Urgent Help frodonet C Programming 15 09-26-2007 12:58 PM
display character size...(quite urgent..) karthi C Programming 10 07-11-2007 09:42 PM
beginner plzz help urgent sara101 C Programming 11 01-14-2007 10:38 PM
printing the output its urgent yviswanadham C Programming 6 12-26-2004 10:27 AM


All times are GMT -6. The time now is 12:06 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22