djbsabkcb 0 Junior Poster in Training

Below is my Julian day program. I have to convert a day into julian and then get todays date and tell how many days from the julian date it is. I am having problems with the output of the julian date is off by 1 day and my difference output is coming out zero every time. Any help would be appreciated.

Thanks

#include <iostream>
#include <string>
#include <cmath>

using namespace std;


long julian ( int year, int month, int day );

int main()
{
    const long int julian_day = 2450000;
    int year = 0;
    int month = 0;
    int day = 0;
    int t_year = 0;
    int m_year = 0;
    int d_year = 0;


    cout << " Enter a year, month, day ( ex. 1323 11 30 or -1400 8 11): ";
    cin >> year;
    cin >> month;
    cin >> day;
    cout << endl << endl;


    long julian_date = julian( year, month, day);

    cout << julian_date << endl;



    cout << " What is today's date in the same format I (ex. 2005 2 22): ";
    cin >> t_year;
    cin >> m_year;
    cin >> d_year;


    long today_date = julian( year, month, day);
    long difference = julian_date - today_date;  //today_date - julian_date;

    cout << difference << endl << endl;

    return 0;
}



    long julian ( int year, int month, int day)
    {

        int j_year = year;
        int j_month = month;
        int j_day = day;

        if ( j_year < 0)

            j_year += 1;

        if ( j_month > 2)

            j_month += 1;

        else
        {
            j_month += 13;
            j_year -= 1;
        }

        long jul =static_cast<long>(floor(365.25 * j_year) + floor(30.6001 * j_month) + j_day + 1720995.0);


    //  if  (j_year <= 1582) {
    //  if  (j_month <= 10) 
    //  if  ( j_day < 15 )  

        if ( j_year < 1582 || ( j_year == 1582 && (j_month < 10 || ( j_month == 10 && j_day < 15))))
            return jul;


        else
        {
            int ja = static_cast<int>(0.01 * j_year);
            jul +=  static_cast<int>(2 - ja + 0.25 * ja);

            return jul;
        }

    }
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.