| | |
C++ help with Julian day program
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
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;
}
}
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;
}
}
![]() |
Similar Threads
- Easter Sunday (C++)
- C++ help with Julian day program revised (C++)
- Need help With this C++ Program..Confused.. (C++)
- system idle and seti@home (Windows Software)
- What is .stt? (Windows NT / 2000 / XP)
Other Threads in the C++ Forum
- Previous Thread: need help with ComboBox (C++, Dialog)
- Next Thread: Double Arrays HELP!!!!!!
| Thread Tools | Search this Thread |
api array arrays based beginner binary bitmap c++ c/c++ calculator char char* class code coding compile compiler console conversion count data database delete deploy developer dll download dynamiccharacterarray email encryption error file forms fstream function functions game getline givemetehcodez graph gui homeworkhelp homeworkhelper iamthwee ifstream input int integer java lib linker list loop looping loops map math matrix memory multiple news node number numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference rpg sorting string strings struct temperature template text text-file tree url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets




