"Develop a program that can be used to calculate the number of days between any two days from 1/1/1900 through 12/31/2099

The main program will call the same function twice- once for each date and have an integer returned to it each time.

The function will prompt for a year, month and day(in that seqeunce)

After receiving both dates, the program will then determine the number of days between the two dates.

The normal year array should contain:

{0, 0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 304, 335, 366};

any help is much appreciated

Recommended Answers

All 12 Replies

We'd love to help you, but you must first read this. Then post your latest attempt, encased within code tags (and tell us what's not working so we don't have to guess).

Thanks

I dunno, maybe actually try it for yourself rather than wandering from board to board in the hope that someone will spoon-feed you the answer.

I'm not looking to be spoon fed an answers
i'm looking for help!!!

>I'm not looking to be spoon fed an answers
Then show that you're willing to try. Post your latest coding attempt at it.

>i'm looking for help!!!
We'll help you once you post what you've already tried.

OK , but how do i paste my code into this message box?
it's not giving me the option

>OK , but how do i paste my code into this message box?

  1. First of all type your message text
  2. Type [code]
  3. Insert some spaces, then type [/code]
  4. Paste your code in between the space that you made between the code tags

I'm assuming of course, that you know how to use your clipboard to copy items. ;)

Ok here is the code

I am new to the array concept, i know how to initialize them but that is it
How would i use the below arrays to add the days together

#include <iostream>
#include <math.h>
#include <stdlib.h>

int main(void)
{
	int month = 0;
	int month2 = 0
	int day = 0;
	int day2 = 0;
	int year = 0;
	int year2 = 0;
	numofdays = 0;
	julianDate = 0;

	const int DaysInMonth[13] = {0,31,28,31,30,31,30,31,31.30,31,30,31};
	const int DaysInYear[13] = {0,0,31,59,90,120,151,181,212,243,273,304,334,365};
	const int DaysInLeapYear[13] = {0,0,31,60,91,121,152,182,213,244,274,305,335,366};
        
	cout << "\n Calculates # of days between dates" << endl;
        cout << "\n give a date (ex: 2 28 2007):"<< endl;
        cin >>  month >> day >> year;
	
	if (month < 0 || month > 12 || day < 0 || day >31 || year > 1900 ||| year <  2099 )
	{
		cout << "One of the numbers you entered is incorrect\n";
		cout << "try entering it again (ex: 2 28 2007): ";
		cin >>  month >> day >> year;
	}

	cout << "\n give another date" << endl;
	cin >> month2 >> day2 >> year2 << endl;
	
	if (month2 < 0 || month2 > 12 || day2 < 0 || day2 >31 || year2 > 1900 ||| year2 <  2099 )
	{
		cout << "One of the numbers you entered is incorrect\n";
		cout << "Try entering it again (ex: 2 28 2007): ";
		cin >>  month2 >> day2 >> year2;
	}

	juliandate =



	cout << month << day << year << endl;
	cout << month2 << day2 << year2 << endl;
	cout << "# of days between these dates is: " << numofdays;
	
}
#include <iostream>
#include <math.h>
#include <stdlib.h>

Alright - so which language are you trying to write in: C or C++? stdlib.h is a C header, and if you really need to use C functions (which I can't seem to find any in your code below) then you can use include <cstdlib> instead.

Since when are there 13 months in a year? And why are you keeping track of the number of days in each year; all you need is a second array for leap year.

Then you can calculate which years are leap years by using a starting year that you know is a leap year (drat, I can't remember when was our last leap year) and then comparing it to the year entered by the user. Hint: you'll need the % (modulos) operator.

The rest should be fairly easy; all you need to do is subtract years and multiply it by the number of days in the year you found earlier, multiply the difference of months by looking up the month array, and then adding the remainig days (if that made any sense at all).

Oops, i don't know why I put 13 in that array

Code i am using is C++

Last night was finally able to get the julian date formula from my instructor is it as follows:

jdate = year - 1900;
jdate = year * 365 +((year-1)/4) + DaysInYear[month] + day

or for leap year:

jdate = year - 1900;
jdate = year * 365 +((year-1)/4) + DaysInLeapYear[month] + day

so later tonight I'm going to add this to my assignment and hopefully it compile just fine, ending this assignemtn and it's important to since I have now fallen behind the rest of the class


if (month < 0 || month > 12 || day < 0 || day >31 || year > 1900 ||| year < 2099 )

I believe you have 3 mistakes here in this line

if (month < 0 || month > 12 || day < 0 || day > 31 || year < 1900 ||| year >2099 )

fixed! :cheesy:

if (month < 0 || month > 12 || day < 0 || day > 31 || year < 1900 ||| year >2099 )

fixed! :cheesy:

Somehow I doubt it... Look at the last ||

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.