Calculate days

A

amackeyb

I need to do a program that calculate the days from a date whatever
since 20XX to January 1st. 2000. How can I do that??
I have this, is it correct???

# include <iostream.h>
# include <conio.h>
void main()
{
int month, day, year, c_year, c_month, t_days;

cout<<"Give a date dd/mm/yy: "<<endl;
cout<<"Day: ";
cin>>day;
cout<<"Month: ";
cin>>month;
cout<<"Year: ";
cin>>year;
clrscr();

c_year=year*365;
c_month=(month-1)*30;
t_days=c_year+c_month+day;

cout<<"Days from"<<day<<"/"<<month<<"/"<<year<<" to January 1st. 2000:
"<<t_days;
}
 
R

red floyd

amackeyb said:
I need to do a program that calculate the days from a date whatever
since 20XX to January 1st. 2000. How can I do that??
I have this, is it correct???

No, it is not. See blow.
# include <iostream.h>
Non-standard header. Use said:
# include <conio.h>
Non-standard header, don't know what it does.

using namespace std;
void main()
Undefined Behavior. Main *MUST* return int.
int main()
{
int month, day, year, c_year, c_month, t_days;

cout<<"Give a date dd/mm/yy: "<<endl;
cout<<"Day: ";
cin>>day;
cout<<"Month: ";
cin>>month;
cout<<"Year: ";
cin>>year;
clrscr();
you don't need to clear the screen. Kill this line (which
then also lets you remove that conio.h).
c_year=year*365;
c_month=(month-1)*30;
What about Jan, Feb, Mar, May, Jul, Aug, Oct, and Dec,
which don't have 30 days?
t_days=c_year+c_month+day;

cout<<"Days from"<<day<<"/"<<month<<"/"<<year<<" to January 1st. 2000:
"<<t_days;

cout << endl;
 
J

Jim Langston

amackeyb said:
I need to do a program that calculate the days from a date whatever
since 20XX to January 1st. 2000. How can I do that??
I have this, is it correct???

# include <iostream.h>
#include said:
# include <conio.h>
I wouldn't bother with this, unless you really wanted to.
void main()
{
int month, day, year, c_year, c_month, t_days;

cout<<"Give a date dd/mm/yy: "<<endl;
cout<<"Day: ";
cin>>day;
cout<<"Month: ";
cin>>month;
cout<<"Year: ";
cin>>year;
clrscr();

c_year=year*365;
c_month=(month-1)*30;

"Thirty days has September, April, June and November, all the rest have
thirty one, except for February which has 28, except on leap years has 31."
 
S

Sumit Rajan

Jim said:
"Thirty days has September, April, June and November, all the rest have
thirty one, except for February which has 28, except on leap years has 31."

Uh?!
 
M

Martin Steen

amackeyb said:
I need to do a program that calculate the days from a date whatever
since 20XX to January 1st. 2000. How can I do that??
I have this, is it correct???

No, it's not that simple.

Visit http://www.javascript.martin-steen.de/astrodate.html
and view the page source. Then you see the "AstroDate"
formula in JavaScript (should be easy to understand for
C-programmers ;)

Best regards, Martin

P.S. litte translation help for german/english:
Jahr = year
Monat = month
Tag = day
 
R

red floyd

Jim said:
er, 29. Yeah. That's what I meant to say :D

Easier one: "... all the rest have thirty one except for February which
is too complicated to discuss right now."
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top