1. How many days are left

Does anyone have any ideas on how do to this in Euphoria:

given month m, day d of the month (not the current date), how would one
calculate the number of days left in the year?  Or, if its easier, how ma=
ny
days have past?

Any ideas would be appreciated.

--Alan
 =

new topic     » topic index » view message » categorize

2. Re: How many days are left

>given month m, day d of the month (not the current date), how would
>one calculate the number of days left in the year?  Or, if its easier,
>how many days have past?

Here's an untested shot at it, does no real error checking:

include get.e

sequence days_month
sequence input
integer month, day, days, inyear

days_month = {31,28,31,30,31,30,31,31,30,31,30,31}

puts(1, "Enter month: ")
input = get(0)
if input[1] = GET_SUCCESS then month = input[2] end if

puts(1, "\nEnter day: ")
input = get(0)
if input[1] = GET_SUCCESS then day = input[2] end if

-- Optional: Check for year and leap year and if so, do
-- (I can't beleive I forgot the 2nd rule of it! (If it's divisable
-- by 4, and something else.... Oh well...)
-- days_month[2] = 29

days = day inyear = 0
for i = 1 to days_month do
    inyear = inyear + days_month[i]
    if i < month then
        days = days + days_month[i]
    end if
end if

puts(1, "Number of days so far (including today) :  ") ? days
puts(1, "Number of days left                     :  ") ? inyear-days

_____________________________________________________________________
You don't need to buy Internet access to use free Internet e-mail.
Get completely free e-mail from Juno at http://www.juno.com
Or call Juno at (800) 654-JUNO [654-5866]

new topic     » goto parent     » topic index » view message » categorize

3. Re: How many days are left

Alan Tu wrote:
> Does anyone have any ideas on how do to this in Euphoria:
> given month m, day d of the month (not the current date), how would
errrrr the current date *is* the day of the month...isn't it? :)

far as the code, this is a more complete version than the other
offered...tested it, seems to work pretty fair, no bad bugs i think.

enjoy--Hawke'
BEGIN CODE
daysleft.ex
----------------------
include get.e
constant
   NormYear={31,28,31,30,31,30,31,30,31,31,30,31},
   LeapYear={31,29,31,30,31,30,31,30,31,31,30,31},
   TRUE= 1,             FALSE = 0,
   SCR = 1,             KB = 0,
   NormYearLen=365,     LeapYearLen=366

sequence Prompt,ThisYear
integer  Year, YearLen, Month, Today,
         DaysPassed, DaysLeft, done

procedure Error(sequence msg)
atom key
   position(23,30)   puts(SCR,msg)
   position(24,33)   puts(SCR,"Press A Key")
   key = wait_key()
end procedure

function InputNum(sequence p,integer min,integer max)
object temp
integer valid
atom num
   valid = FALSE
   while not valid do
        clear_screen()
        position (10,15)   puts(SCR,p)
        temp = get(KB)
        if temp[1]=GET_SUCCESS then num=temp[2]   end if
        if (num>=min) and (num<=max) and integer(num) then
           valid = TRUE
        end if
   end while
   return num
end function

--MAIN
   Prompt="Enter last 2 digits of current year(00..99):"
   Year  =InputNum(Prompt,0,99)
   if remainder(Year,4) = 0 then
        ThisYear = LeapYear
        YearLen  = LeapYearLen
   else
        ThisYear = NormYear
        YearLen  = NormYearLen
   end if
   Prompt="Enter the current Month(1..12):"
   Month =InputNum(Prompt,1,12)
   done = FALSE
   while not done do
        Prompt="Enter the current date of today(1.." &
                       sprintf("%d",ThisYear[Month]) & "):"
        Today =InputNum(Prompt,1,ThisYear[Month])
        if Today > ThisYear[Month] then
             Error("Invalid Date Entered")
        else done = TRUE
        end if
   end while
   DaysPassed = 0       DaysLeft = YearLen
   for i = 1 to (Month-1) do
        DaysPassed = DaysPassed + ThisYear[i]
        DaysLeft   = DaysLeft   - ThisYear[i]
   end for
   DaysPassed = DaysPassed + Today
   DaysLeft   = DaysLeft   - Today
   clear_screen()
   printf(SCR,"Number of days that have passed:%d\n",DaysPassed)
   printf(SCR,"Number of days left in the year:%d\n",DaysLeft)
----------------------------
END CODE

new topic     » goto parent     » topic index » view message » categorize

4. Re: How many days are left

errrr you can actually cut this code down a bit...
(i think) you can remove the lines:

--kill these 2
>    done = FALSE
>    while not done do

--leave these 2
Prompt="Enter the current date of today(1.." &
          sprintf("%d",ThisYear[Month]) & "):"
Today =InputNum(Prompt,1,ThisYear[Month])


--kill all these
>         if Today > ThisYear[Month] then
>              Error("Invalid Date Entered")
>         else done = TRUE
>         end if
>    end while


a case of redundant error checking, i added the
ThisYear[Month] to the InputNum line, thereby automatically
sending valid dates back...
doesn't hurt to leave it in except for speed...

new topic     » goto parent     » topic index » view message » categorize

5. Re: How many days are left

Hawke,

Thanks for the effort.  You might or might not know I released my
application.  I still want to spruce it up, with types and such.

>   if remainder(Year,4) =3D 0 then

Look at my code, and you'll see some more error-checking.  Years divisibl=
e
by 4 are leap years, except years divisible by 100.  1900 and 1800 are no=
t
leap years.  However, years divisible by 400 are leap years, such as 2000=
=2E =

Naturally, in computer lingo, these rules are reversed.  Interesting, eh?=


--Alan

P.S.  If you are in the US, have a pleasant labor day weekend, and have a=

good weekend regardless.
 =

new topic     » goto parent     » topic index » view message » categorize

6. Re: How many days are left

Hey, anyone interested in true color 3d graphics demo?

    - John Leith
    Red Dagger

new topic     » goto parent     » topic index » view message » categorize

7. Re: How many days are left

Karolyn Leith wrote:
> Hey, anyone interested in true color 3d graphics demo?
> - John Leith--Red Dagger
perhaps... what language is it written in? euphoria?
is it freeware?
is it a library or an application?
does it support DIRECTtothebluescreenofdeathX? 3dfx? opengl?

</hallucinations>
</delusions>

:>   --Hawke'

new topic     » goto parent     » topic index » view message » categorize

8. Re: How many days are left

Alan Tu wrote:
> Hawke,
>Thanks for the effort.
yer quite velcome :)

> You might or might not know I released my application.
yeah my mailer burped (pardon!) and held all mail for
a couple hours inbound/outbound, so our posts got
crisscrossed (saw that yours had actually been received
by my host before mine actually got out of my hosts
mail spooler...)


>Look at my code, and you'll see some more error-checking.
>Years divisible by 4 are leap years, except years divisible
>by 100.  1900 and 1800 are not leap years.  However, years
>divisible by 400 are leap years, such as 2000.
yeah, i can add that to the code if you like... or you can as
well i'm sure :)

take care--Hawke'

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu