| | |
C++ help with Julian day program revised
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
Below is my new code for this julian day program. I have fixed some of the errors I mentioned earlier. However, the day is still one short for the julian day and my conditional if statement seems to be the problem. I have tried a couple of ways to fix it. Any suggestions.
Thanks.
Code tags added. -Narue
Thanks.
C++ Syntax (Toggle Plain Text)
// Assignment #3, Programming I, Summer 2005 // Name: Darius Juan Bloomer #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 t_month = 0; int t_day = 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(ex. 2005 2 22): "; cin >> t_year; cin >> t_month; cin >> t_day; long today_date = julian( t_year, t_month, t_day); long difference = 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; } }
•
•
•
•
Originally Posted by djbsabkcb
Below is my new code for this julian day program. I have fixed some of the errors I mentioned earlier. However, the day is still one short for the julian day and my conditional if statement seems to be the problem. I have tried a couple of ways to fix it. Any suggestions.
•
•
•
•
C:\Test>testpp
Enter a year, month, day ( ex. 1323 11 30 or -1400 8 11): 2005 7 7
2453559
What is today's date in the same format(ex. 2005 2 22): 2005 7 8
1
C:\Test>testpp
Enter a year, month, day ( ex. 1323 11 30 or -1400 8 11): 2005 7 6
2453558
What is today's date in the same format(ex. 2005 2 22): 2005 7 8
2
"One of the methods used by statists to destroy capitalism consists in establishing controls that tie a given industry hand and foot, making it unable to solve its problems, then declaring that freedom has failed and stronger controls are necessary." --Ayn Rand
•
•
Join Date: Jun 2005
Posts: 60
Reputation:
Solved Threads: 5
C++ Syntax (Toggle Plain Text)
long jul =static_cast<long>(floor(365.25 * j_year) + floor(30.6001 * j_month) + j_day + 1720995.0);
and second. remove the floor() - and it is doing it corectly.
>Could you better describe the problem?
As far as I know it is showing 1 day less in some years, (not when calculating, but the julian date is 1 less than is shuld be).
![]() |
Similar Threads
- Easter Sunday (C++)
- C++ help with Julian day program (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: Array Problem
- Next Thread: Linked stack modification issue
Views: 4552 | Replies: 4
| Thread Tools | Search this Thread |
Tag cloud for C++
6 api application array arrays assignment based beginner binary c++ c/c++ calculator char char* class classes code coding compile compiler console conversion convert count data database delete developer display dll dynamiccharacterarray email encryption error file format forms fstream function functions game generator givemetehcodez graph iamthwee ifstream image input int java lib list loop looping loops map math matrix memory multidimensional multiple newbie news number numbertoword output pointer problem program programming project python random read recursion recursive reference return rpg search sort sorting string strings struct template templates text tree url variable vector video visual visualstudio win32 windows winsock wordfrequency wxwidgets






