C++ output date in number of days per year

for example
user puts in the month as 1-12
the day for whatever month
and the year, which has to include leapyears
leap years only occur when the year is divisible by 4 y%4==o or if divisible by 400 but NOT 100, so 2000 is a leap year but not 2100

so if somebody puts in month 1 day 1 and 2005 it will say 1
if it's month 12 and day is 31 and year is 2005 it will say 365
but if it was 2004 it would say 366
month 3, day 10, year 2005, would be 31+28+10 or just 69

can anybody do this
i guess it needs boolean stuff for the leap year
and a few switch and case things for the rest

i'm not feeling it though

i got one to kind of work with if statements but not correctly, and it was long
 
508
1
Code:
if (year%4 == 0 && !(year%100 == 0 && year%400 != 0))
    DaysPerMonth = {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
else
    DaysPerMonth = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

for (i=0; i<month - 1; i++)
    ndays += DaysPerMonth[i];

ndays += day;
 
351
1
Well put :)
 
and what am i putting in right above that (i've been doing this for less than a month so bear with me)
i dont know what exactly i am calling what
int days, etc.???
 
1,349
2
pick up a standard C OR C++ book. there are tutorials about such things usual in those or there are websites...sorry I cant remember C++tutorials.com cplus.com i think are some...
 
yeah i got a book, but it's no good, or it's too good
 
351
1
neurocomp2003 said:
pick up a standard C OR C++ book. there are tutorials about such things usual in those or there are websites...sorry I cant remember C++tutorials.com cplus.com i think are some...
heh I dont think thats a legal URL format, only alpha-numerical chars are allowed :tongue2:
 

Related Threads for: C++ output date in number of days per year

  • Posted
Replies
2
Views
2K
  • Posted
Replies
4
Views
9K
  • Posted
Replies
8
Views
2K
Replies
5
Views
11K
  • Posted
2
Replies
36
Views
4K
  • Posted
Replies
21
Views
3K
Replies
5
Views
8K
  • Posted
Replies
2
Views
754

Physics Forums Values

We Value Quality
• Topics based on mainstream science
• Proper English grammar and spelling
We Value Civility
• Positive and compassionate attitudes
• Patience while debating
We Value Productivity
• Disciplined to remain on-topic
• Recognition of own weaknesses
• Solo and co-op problem solving
Top