Site hosted by Angelfire.com: Build your free website today!
« March 2006 »
S M T W T F S
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
Entries by Topic
All topics  «
Blog Tools
Edit your Blog
Build a Blog
RSS Feed
View Profile
Open Community
Post to this Blog
You are not logged in. Log in
C++ Programs from Random Places
Friday, 17 March 2006
Find the Day of the Year
//THIS CALCULATES THE DAY OF THE YEAR(OUT OF 365/366)
//**NOTE**: THIS MATERIAL IS NOT COPYRIGHTED AND IS FREE FOR
//PERSONAL USE AND DISTRIBUTION
#include
using namespace std;

bool febdays(int year)
//PURPOSE: determines if year is a leap year
//PRECONDITION: uses certain divisors to find leap years
//POSTCONDITION: returns true or false for variable year
{
if(year%4==0 && year%100!=0){ //any year evenly divisible by 4 but not by 100 and 400
return true;
}
else if(year%4==0 && year%100==0 && year%400==0){
return true;
}
else if(year%4==0 && year%100==0 && year%400!=0){
return false;
}
else{
return false; //for years not evenly divisible by 4
}
}
int daynum(int month, int day,int year)
//PURPOSE: finds day of year
//PRECONDITION: takes in month, day, and year entered
//POSTCONDITION: returns day of year
{
int julian_day=0; //a julian day refers to the day on the Julian calendar
if(month==1){
julian_day=0+day;
}
else if(month==2){
julian_day=31+day;
}
else if(month==3){
if(febdays(year)==true){
julian_day=60+day;
}
else{
julian_day=59+day;
}
}
else if(month==4){
if(febdays(year)==true){
julian_day=91+day;
}
else{
julian_day=90+day;
}
}
else if(month==5){
if(febdays(year)==true){
julian_day=121+day;
}
else{
julian_day=120+day;
}
}
else if(month==6){
if(febdays(year)==true){
julian_day=152+day;
}
else{
julian_day=151+day;
}
}
else if(month==7){
if(febdays(year)==true){
julian_day=182+day;
}
else{
julian_day=181+day;
}
}
else if(month==8){
if(febdays(year)==true){
julian_day=213+day;
}
else{
julian_day=212+day;
}
}
else if(month==9){
if(febdays(year)==true){
julian_day=244+day;
}
else{
julian_day=243+day;
}
}
else if(month==10){
if(febdays(year)==true){
julian_day=274+day;
}
else{
julian_day=273+day;
}
}
else if(month==11){
if(febdays(year)==true){
julian_day=305+day;
}
else{
julian_day=304+day;
}
}
else if(month==12){
if(febdays(year)==true){
julian_day=335+day;
}
else{
julian_day=334+day;
}
}
return julian_day;
}
int main()
//PURPOSE: finds julian day on calendar(0-365/366)
//PRECONDITION: asks user for month, day, and year
//POSTCONDITION: returns julian day
{
int month, day, year;
cout<<"Enter the month: "< cin>>month;
if(month<1 || month>12){
return 0;
}
cout<<"Enter the day: "< cin>>day;
if(day<1){ //even if "day" is > the number of days in the month, the correct Julian day will be returned
return 0;
}
cout<<"Enter the year: "< cin>>year;
cout< return 0;
}

Posted by poetry/maddoxtheconqueror at 12:01 AM CST
Post Comment | Permalink | Share This Post

View Latest Entries