An algorhytm

7 replies [Last post]
Joined: 04/29/2011

Sorry guys, can I ask you some help?

I need to make an algorhytm for homework.
It says: Write an algorhytm that givven two dates, calculate the distance between them in days.

Please help!!! Puzzled

P.S Correct me if I misspeled something.

Joined: 08/06/2010

That's fine, it's in the Pictures of your Cat section. Smile

So it this meant to be a purely mathematical algorithm, written as a function of two numbers? Or is it meant to be a computer program? Or just a way that you can calculate it with pencil and paper?

However you're doing it, the first thing that you will want to do is add the days from the previous months. So February 2nd would become 33, because you add January's 31 days to the 2. December 31 would be either 365 or 366, depending if it is a leap year or not.

Once you've found a good way to convert them to numbers like that, it becomes a simple subtraction problem (you need the difference).

Hope this is what you were looking for.

Another Planet finally has an official release! Download chapters 1 through 3 here! Thank you for waiting so long while I kept starting over.

Joined: 04/29/2011

I think that would help, but I need an pseudocode. I think you know what it means.
Actually it should be considered like a source code of a programm, but not in C++ or Java, but English. Smile

Joined: 08/06/2010

Yes, I know. Smile

You're going to need to implement it yourself, but an easy way to add all those months in would be some sort of array: 31, 28+31, 31+28+31, 30+31+28+31... Then add in the value stored in the array for that month.

Another Planet finally has an official release! Download chapters 1 through 3 here! Thank you for waiting so long while I kept starting over.

Joined: 04/29/2011

Oh, thanks! I'll implement it with the array how you said. Nobody in my class can't do this one, so I'll be the first Evil Thanks!

P.S. First time used this Evil smiley.

Joined: 07/08/2011

You can use an equation like x - y = d where x & y are the days into the year and d is the difference in days between them.

f(x,y) being the difference between the xth day of the year and the yth day of the year.

Example: d(February 9,January 12)

let d = difference in days between the dates

first calculate how many days in total the date is into the year (what AP said)
x = February 9, or 40
y = January 12, or 12

Then, subtract the two
x - y = d
40 - 12 = d
28 = d

Therefore, the difference between February 9th and January 12th is 28 days.

Joined: 04/29/2011

Thank you very much guys! Laughing out loud

Joined: 02/20/2011

2nd person with a homework problem Tongue

-_-