Hi guys, trying to get a day number from 1 - 366 for a specific date.
I've been working on this for a while. I can't seem to figure out. I'm not asking for an answer, just a push in the right direction. So far here is what I have for code:

#include <iostream> 
using namespace std;

void main()
{

	int a, y, m, year, month, yearBefore, day;
	int day1;
	int julianDay = 0;	

	cin>>month>>day>>year;
	
	for(yearBefore=year; yearBefore >= (year-1); yearBefore--)
	{
	a = (14 - month) / 12;
	y = yearBefore + 4800 - a;
	m = month + 12 * a - 3;
	
	julianDay = day + (153 * m + 2) / 5 + y *  365 + y / 4 - y/100 + y/400 - 32045;
	
	if(day1 = 0)
	{
	day1 += julianDay;
	}	
	if(day1 > julianDay)	
	{
	 day1 -= julianDay;
	}
			
	day = 31;
	month = 12;
	}
	cout << day1;
	

	
}

I keep trying to find a way to get it to subtract the second julian day from the first. Please help!

void main is a crime. Always use int main. http://cppdb.blogspot.com/2009/02/should-i-use-void-main-or-int-main-or.html

if( day=0) will always be true. Use if(day == 0) instead. There is a difference between = and ==. The former is an assignment operator. The later is a logical operator, it evaluates whether the LHS and RHS are equal or not.

I don't know julian system so I cannot help you in logic.
Another advice. Try to use more descriptive names of variables instead of a,m,y.
I cannot interpret what does these variable are created for. Use a bigger name. like current_year, current_month. It will surely need you to type more, but it will clear out your path to become a good programmer.

[edit] I was reading about julian system of date. It turns out that the variable you used a,y,m are standard variables. So sorry to intercept. But my advice should be followed in all the other program you will write.

Comments
Very good !!

void main is a crime. Always use int main. http://cppdb.blogspot.com/2009/02/should-i-use-void-main-or-int-main-or.html

if( day=0) will always be true. Use if(day == 0) instead. There is a difference between = and ==. The former is an assignment operator. The later is a logical operator, it evaluates whether the LHS and RHS are equal or not.

I don't know julian system so I cannot help you in logic.
Another advice. Try to use more descriptive names of variables instead of a,m,y.
I cannot interpret what does these variable are created for. Use a bigger name. like current_year, current_month. It will surely need you to type more, but it will clear out your path to become a good programmer.

[edit] I was reading about julian system of date. It turns out that the variable you used a,y,m are standard variables. So sorry to intercept. But my advice should be followed in all the other program you will write.

Thank you very much. I did not know that there was a difference between '=' and "==". This was the exact fix I needed! Yeah I am really only using void because this is just a separate file I created to test one of many functions in a bigger program.

This article has been dead for over six months. Start a new discussion instead.