Re: How many days are left

new topic     » goto parent     » topic index » view thread      » older message » newer message

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 thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu