473,395 Members | 1,996 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Calculate days

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;
}

Oct 10 '06 #1
8 2392
amackeyb wrote:
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 <iostream>
# 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;
}
Oct 10 '06 #2
red floyd wrote:
>void main()
Undefined Behavior. Main *MUST* return int.
I suspect it's ill-formed syntax. That occurs before any behavior.

--
Phlip
http://www.greencheese.us/ZeekLand <-- NOT a blog!!!
Oct 10 '06 #3

"amackeyb" <am******@gmail.comwrote in message
news:11**********************@i3g2000cwc.googlegro ups.com...
>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 <iostream>
# 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."
t_days=c_year+c_month+day;

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

Oct 10 '06 #4
Jim Langston wrote:
>
"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?!
Oct 10 '06 #5
Phlip wrote:
red floyd wrote:
>>void main()
>Undefined Behavior. Main *MUST* return int.

I suspect it's ill-formed syntax. That occurs before any behavior.
Whoops! You're right!
Oct 10 '06 #6

"Sumit Rajan" <su*********@gmail.comwrote in message
news:4p************@individual.net...
Jim Langston wrote:
>>
"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?!
er, 29. Yeah. That's what I meant to say :D

Oct 10 '06 #7
Jim Langston wrote:
"Sumit Rajan" <su*********@gmail.comwrote in message
news:4p************@individual.net...
>Jim Langston wrote:
>>"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?!

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."
Oct 10 '06 #8
amackeyb wrote:
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

Oct 10 '06 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: JP SIngh | last post by:
Hi All I need to calculate the number of working days between the two dates entered on an ASP page. I am not that great a coder in ASP and was wondering if someone can help. Basically the...
7
by: Sam | last post by:
Hi, I use C# in my ASP.NET projects. Here's what I need to do: I want to add x business days to a given date i.e. add 12 business days to today's date. What is the best, fastest and most...
9
by: howzit | last post by:
I have a set date in my MySQL database that records when a Sales Lead is established and I echo that date as $row_rsLead; I need to be able to calculate how many days that lead has existed....
5
by: Beemer Biker | last post by:
I cant seem to get that date into any DateTime to make my calculation directly by subtracting "01-01-0000" from "now". After reading this:...
7
by: ngweixiong | last post by:
Hi, I have a Ms Access query which i used to calculate how many times the leadtime is a) less than 7 days b) 7-14 days c) more than 14 days With the query results, i will like to convert...
1
by: ndindi22 | last post by:
Can someone plz help me. I'm working on leave application, have to calculate number of leave days available, starting from Startdate to Enddate of a contract. Where an employee get 1 day leave...
3
by: Libber39 | last post by:
Hi everyone, Have a query on how to calculate the amount of weeks and days contained in a number in an access query. ie: the difference in days between 2 dates amounts to 17 days. I want to now...
4
by: shilpareddy2787 | last post by:
Hello, I have some total values, I want to calculate percenatge of these Total Values. I want to divide the total with No. Of working Days Excluding Saturdays and Sundays in a given period. ...
15
by: student4lifer | last post by:
Hello, I have 2 time fields dynamically generated in format "m/d/y H:m". Could someone show me a good function to calculate the time interval difference in minutes? I played with strtotime() but...
5
FishVal
by: FishVal | last post by:
IMHO, the following is not a how-to-do instruction to solve a particular problem but more a concept-proof stuff demonstrating possibilities of SQL. So, let us say the problem is to calculate...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.