Advertisement

There's no such thing as a stupid question, but they're the easiest to answer.
Login
Search

Advertisement

Software Development Software Development
Search Search
Search for:
Tech Support Guy > > >

how many days has it been this year?


(!)

2xaron's Avatar
2xaron 2xaron is offline
Junior Member with 5 posts.
THREAD STARTER
 
Join Date: Nov 2006
11-Nov-2006, 11:58 PM #1
how many days has it been this year?
I am trying to make a program where the user inputs a date, and the output will be how many days have passed so far in ther year. using c++ this program does not work! just my ideas so far
__________________________________________________________________________

cin >> day , month , year;
for (q = 0; q < month; ++i){
int q;
cin >> q;
switch (q){
case 1: case 3: case 5: case 7: case 8: case 10: case 12:
monthdays = 31;
break;
case 2:
monthdays = 28;
break;
case 4: case 6: case 9: case 11:
monthdays = 30;
break;
}
totaldays = (monthdays + monthdays);
cout << totaldays;
}
Squashman's Avatar
Trusted Advisor with 19,684 posts.
 
Join Date: Apr 2003
Location: 1265 Lombardi Ave
12-Nov-2006, 12:13 AM #2
2xaron's Avatar
2xaron 2xaron is offline
Junior Member with 5 posts.
THREAD STARTER
 
Join Date: Nov 2006
12-Nov-2006, 01:07 AM #3
ya but i need the logic to the thing ne ideas to build upon what i already have?
dquigley's Avatar
dquigley dquigley is offline
Computer Specs
Senior Member with 112 posts.
 
Join Date: Apr 2006
Location: Woodinville, WA
Experience: Advanced
12-Nov-2006, 01:21 AM #4
The easiest way to do this is using Julian dates. You can find some raw routines here:

http://www.silverglass.org/code/Date.html
Squashman's Avatar
Trusted Advisor with 19,684 posts.
 
Join Date: Apr 2003
Location: 1265 Lombardi Ave
13-Nov-2006, 06:58 PM #5
Quote:
Originally Posted by 2xaron
ya but i need the logic to the thing ne ideas to build upon what i already have?
I am not going to completely write the code for you. You need to use Julian dates.
AGCurry's Avatar
AGCurry AGCurry is offline
Senior Member with 431 posts.
 
Join Date: Jun 2005
Location: Kansas City area
Experience: advanced but learning
14-Nov-2006, 08:48 AM #6
In the Unix world, I would use the library functions for date and time. Squashman has given you a couple of good links.

Maybe you're taking a class and aren't supposed to know about those yet. If so, it looks like your switch statement is pretty much okay, but you DO need to figure out how to sum the desired result. It looks like you need some sort of iteration.
lotuseclat79's Avatar
Member with 20,583 posts.
 
Join Date: Sep 2003
Location: -71.45091, 42.27841
16-Nov-2006, 09:59 AM #7
Good advice about Julian calanders and iteration.

Dates, as we know them today, are specified, for example, in terms of month, day, year or day, month, year or year, month, day or year, day or day, year. Then again, the number of days in a year can vary from 365 to 366 depending on whether it is a leap year. Knowing the day of the year requires mapping to a calendar date or visa versa, and requires a way to transform between the two.

If you needed to know the the day of the week, there are only 14 calendars: one map where Jan 1st occurs on each day of the week for a non-leap year, and another map where Jan 1st occurs on each day of the week for a leap year - but that is not within the requirements of solving your problem.

In your message, you did not account for a 29 day February for a leap year.

Good luck,

-- Tom
__________________
The independence created by philosophical insight is - in my opinion - the mark of distinction
between a mere artisan or specialist and a real seeker after truth. - Einstein 1944
Imagination is more important than knowledge. - Einstein
As Seen On

BBC, Reader's Digest, PC Magazine, Today Show, Money Magazine
WELCOME TO TECH SUPPORT GUY!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.


(clock)
THIS THREAD HAS EXPIRED.
Are you having the same problem? We have volunteers ready to answer your question, but first you'll have to join for free. Need help getting started? Check out our Welcome Guide.

Search Tech Support Guy

Find the solution to your
computer problem!




Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools


WELCOME
You Are Using: Server ID
Trusted Website Back to the Top ↑

Content Relevant URLs by vBSEO 3.3.2