#include <iostream>
#include <iomanip>
usingnamespace std;
double d,m,y,a,b;
double jd;
int main()
{
cout << "d" << endl;
cin >> d;
cout << "m" << endl;
cin >> m;
cout << "y" << endl;
cin >> y;
cout << endl;
cout << setprecision (16);
if (m>2) {
y=y;
m=m;
} elseif ( m <= 2 ) {
y -= 1;
m += 12;
}
a = (y/100);
b = 2 - a + (a / 4);
jd = (365.25 * (y +4716)) + (30.6001 * (m+1)) + d + b - 1524.5;
cout << "= " << jd << endl;
cin.get();
return 0;
}
does any body know why, when I use cin.get() function my program crashes,
this is a reoccurring problem in all of my programs so I have to revert back to the system function.
@buffbill Can some one explain how to use this formula. I don't understand because when I put in a non decimal date I get a decimal jd. Also I don't understand how to subtract the two dates and get the years, days, hours, minutes, seconds. Also buffbill you told me almost nothing about this formula. I need to know a little bit more to know how to complete this program.
BTW I don't know how you got yesterdays date (2455217.17222) as 1000 years ago and a couple hours off. I would appreciate if you went into greater detail about your formula and what i am trying to do. I am confused because I researched my previous formula extensively, as where I can't even find this one online.
thanks, It looks a lot better.
But the thing is I still don't know how to use this formula correctly for what I am doing.
And buffbill can only explain that to me since he has the source. http://cplusplus.com/forum/general/18398/page2.html#msg95859
Also heilos, I have never gotten how to pause my program correctly...
A lot of source code examples I see, don't appear to pause the program. i.e Opens then closes immediately
Dumb question \/
When you use return 0; does that make it pause?
Huh? It crashes? As in, you get an error message from the operating system?
It doesn't show a error from the OS. It just doesn't pause the program, as i thought cin.get() does.
Well that's not really a crash. And no, returning in and of itself doesn't pause; it just "ends" the function. In this case, it's main so control is returned to the OS, which closes your console window among other things seeing as how your program is finished.
If cin.get() isn't pausing, it's possible that there is other input left over in the buffer that cin is reading at that point. You'll want to empty the buffer completely before asking for the final input so that stops being an issue.
And no, returning in and of itself doesn't pause; it just "ends" the function.
I knew that I just was afraid to say it.
But, (to me) there seems to be another reason for why this is happening.
again I think this is a dumb question, Can you give me a example of input still left in the buffer.
buffbill http://cplusplus.com/forum/general/18398/page2.html#msg95859
No disrespect, but giving me a formula then vaguely telling me how to use it isn't very helpful.
I googled alot and I still cant find a pdf for Astronomical algorithms 1999 Jean Meeus.
So maybe more information can help.
i.e Can i be linked to where you are seeing this formula.
and more info i.e from when to when is this formula good for, How do I use it for what I am trying to do.
ugh... I can't think tonight... sorry for the about 10 edits.
Helios, after you typed in the date did it display the answer?
That is what's wrong.
For me once I finish typing in the day, It closes and disregards cin.get()
If cin.get() isn't pausing, it's possible that there is other input left over in the buffer that cin is reading at that point. You'll want to empty the buffer completely before asking for the final input so that stops being an issue.
If so, how so I empty the buffer?
And yes, you can pass user input to functions. If that wasn't the case, programming wouldn't make much sense.
Yeah I knew it would (should) work. But I wasn't sure because it is not working for me.
My Question is did the program B.A.P develop work with preciseness since his figures was imperfect, being possible for it to come in whole on leap day, but not possible any time else with out compensation for the leap year even at the 2 before that year which splits into the final six hour and go into beginning six hour of two different days. Helios that is exquisiteness in ur programming ability beside word problem solving ability how long u been programming.
My Question is did the program B.A.P develop work with preciseness since his figures was imperfect, being possible for it to come in whole on leap day but not possible any time else with out compensation for the leap year even at the 2 before that year which splits into the final six and go into beginning six of two different days. Helios that is exquisiteness in ur programming ability beside word solving ability how long u been programming.
What?? Can you speak in simpler terms?
@helios, If the problem is the buffer, Then std::cout<< std::endl;
should empty it and cin.get() should work right?
No, it won't.
This subject has already been discussed to death on this forum. Personally, I don't know why someone would subject themselves to this torture when it's far easier to just run the program from a fucking console.