# how many days has it been this year?

Discussion in 'Software Development' started by 2xaron, Nov 11, 2006.

Not open for further replies.

Joined:
Nov 10, 2006
Messages:
5
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;
}

Joined:
Apr 4, 2003
Messages:
19,749

Joined:
Nov 10, 2006
Messages:
5
ya but i need the logic to the thing ne ideas to build upon what i already have?

5. ### dquigley

Joined:
Apr 17, 2006
Messages:
112

Joined:
Apr 4, 2003
Messages:
19,749
I am not going to completely write the code for you. You need to use Julian dates.

7. ### AGCurry

Joined:
Jun 15, 2005
Messages:
431
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.

8. ### lotuseclat79

Joined:
Sep 12, 2003
Messages:
20,583

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

As Seen On

### Welcome to Tech Support Guy!

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

over 733,556 other people just like you!