A little program in Pascal

Hi everybody!

I want to make a program in pascal that calculates the number of days of a person. The information that is written from the keyboard is the date of birth and the actual day. And i must calculate the number of days between this period. Please help me if you can. Thanks!

Comments

  • : Hi everybody!
    :
    : I want to make a program in pascal that calculates the number of
    : days of a person. The information that is written from the keyboard
    : is the date of birth and the actual day. And i must calculate the
    : number of days between this period. Please help me if you can.
    : Thanks!
    :
    I've written this kind of program before. Trust me, the best solultion is to write a function that will take a year, month, and day as input and return a Julian date. You can then just subtract the earlier Julian date from the later Julian date.

    In computer programming a Julian date is the number of days since the beginning of the year (Jan 1 = 1). For our purposes we need to define a Julian date as the number of days since some arbitrary date, say Jan 1 of the year zero. What I lay our here is based on the Gregorian calendar, which has been in use since the 16th century. Dates before that based on the Julian calendar may or may not give correct results.

    Trust me, this approach is ultimately simpler than trying to subtract one date from another, where you may have to borrow days from the previous month, which means you have to determe how many days were in the previous month, and borrowing months from the privious year which may be a leap year. It's a mess.

    [code]
    Program Days ;

    Function Julian (Year: Word ; Month, Day : Byte) : LongInt ;

    Function IsLeap (Year : LongInt) : Boolean ;
    {
    a year is a leap year IF it's divisible by 4
    UNLESS it's also divisible by 100, then it's
    a leap year ONLY if it divisible by 400
    }
    begin
    if Year DIV 4 = 0 then begin
    if Year DIV 100 = 0 then begin
    if Year DIV 400 = 0 then
    IsLeap := TRUE
    else
    IsLeap := FALSE
    end
    else
    IsLeap := TRUE
    end
    else
    IsLeap := FALSE
    end ;

    Function DaysPriorToThisYear (Year : LongInt) : LongInt ;

    Var
    i, Count : LongInt ;

    begin
    Count := 0 ;

    for i := 1 to Year - 1 do
    if IsLeap(i) then
    Count := Count + 366
    else
    Count := Count + 365 ;

    DaysPriorToThisYear := Count
    end ;

    Function DaysPriorToThisMonth (Year, Month : LongInt) : LongInt ;

    CONST
    MonthDays : Array [FALSE .. TRUE, 1 .. 12] of LongInt
    = ((31,28,31,30,31,30,31,31,30,31,30,31),
    (31,29,31,30,31,30,31,31,30,31,30,31)) ;

    Var
    i, Count : LongInt ;

    begin
    Count := 0 ;

    for i := 1 to Month - 1 do
    if IsLeap(Year) then
    Count := Count + MonthDays[TRUE, i]
    else
    Count := Count + MonthDays[FALSE, i] ;

    DaysPriorToThisMonth := Count
    end ;

    begin
    Julian := DaysPriorToThisYear(Year)
    + DaysPriorToThisMonth(Year,Month)
    + Day
    end ;

    Var
    Year0, Year1, Month0, Month1, Day0, Day1, BirthDay, Today : LongInt ;

    begin
    Write ('Enter year of birth: ') ; ReadLn (Year0) ;
    Write ('Enter month of birth: ') ; ReadLn (Month0) ;
    Write ('Enter day of birth: ') ; ReadLn (Day0) ;
    WriteLn ;

    Write ('Enter today''s year: ') ; ReadLn (Year1) ;
    Write ('Enter today''s month: ') ; ReadLn (Month1) ;
    Write ('Enter today''s day: ') ; ReadLn (Day1) ;

    BirthDay := Julian (Year0, Month0, Day0) ;
    Today := Julian (Year1, Month1, Day1) ;

    WriteLn (Today :10) ;
    WriteLn (Birthday:10) ;

    WriteLn ('The person is ', Today - BirthDay, ' days old.')
    end.
    [/code]
  • : : Hi everybody!
    : :
    : : I want to make a program in pascal that calculates the number of
    : : days of a person. The information that is written from the keyboard
    : : is the date of birth and the actual day. And i must calculate the
    : : number of days between this period. Please help me if you can.
    : : Thanks!
    : :
    : I've written this kind of program before. Trust me, the best
    : solultion is to write a function that will take a year, month, and
    : day as input and return a Julian date. You can then just subtract
    : the earlier Julian date from the later Julian date.
    :
    : In computer programming a Julian date is the number of days since
    : the beginning of the year (Jan 1 = 1). For our purposes we need to
    : define a Julian date as the number of days since some arbitrary
    : date, say Jan 1 of the year zero. What I lay our here is based on
    : the Gregorian calendar, which has been in use since the 16th
    : century. Dates before that based on the Julian calendar may or may
    : not give correct results.
    :
    : Trust me, this approach is ultimately simpler than trying to
    : subtract one date from another, where you may have to borrow days
    : from the previous month, which means you have to determe how many
    : days were in the previous month, and borrowing months from the
    : privious year which may be a leap year. It's a mess.
    :
    : [code]:
    : Program Days ;
    :
    : Function Julian (Year: Word ; Month, Day : Byte) : LongInt ;
    :
    : Function IsLeap (Year : LongInt) : Boolean ;
    : {
    : a year is a leap year IF it's divisible by 4
    : UNLESS it's also divisible by 100, then it's
    : a leap year ONLY if it divisible by 400
    : }
    : begin
    : if Year DIV 4 = 0 then begin
    : if Year DIV 100 = 0 then begin
    : if Year DIV 400 = 0 then
    : IsLeap := TRUE
    : else
    : IsLeap := FALSE
    : end
    : else
    : IsLeap := TRUE
    : end
    : else
    : IsLeap := FALSE
    : end ;
    :
    : Function DaysPriorToThisYear (Year : LongInt) : LongInt ;
    :
    : Var
    : i, Count : LongInt ;
    :
    : begin
    : Count := 0 ;
    :
    : for i := 1 to Year - 1 do
    : if IsLeap(i) then
    : Count := Count + 366
    : else
    : Count := Count + 365 ;
    :
    : DaysPriorToThisYear := Count
    : end ;
    :
    : Function DaysPriorToThisMonth (Year, Month : LongInt) : LongInt ;
    :
    : CONST
    : MonthDays : Array [FALSE .. TRUE, 1 .. 12] of LongInt
    : = ((31,28,31,30,31,30,31,31,30,31,30,31),
    : (31,29,31,30,31,30,31,31,30,31,30,31)) ;
    :
    : Var
    : i, Count : LongInt ;
    :
    : begin
    : Count := 0 ;
    :
    : for i := 1 to Month - 1 do
    : if IsLeap(Year) then
    : Count := Count + MonthDays[TRUE, i]
    : else
    : Count := Count + MonthDays[FALSE, i] ;
    :
    : DaysPriorToThisMonth := Count
    : end ;
    :
    : begin
    : Julian := DaysPriorToThisYear(Year)
    : + DaysPriorToThisMonth(Year,Month)
    : + Day
    : end ;
    :
    : Var
    : Year0, Year1, Month0, Month1, Day0, Day1, BirthDay, Today : LongInt ;
    :
    : begin
    : Write ('Enter year of birth: ') ; ReadLn (Year0) ;
    : Write ('Enter month of birth: ') ; ReadLn (Month0) ;
    : Write ('Enter day of birth: ') ; ReadLn (Day0) ;
    : WriteLn ;
    :
    : Write ('Enter today''s year: ') ; ReadLn (Year1) ;
    : Write ('Enter today''s month: ') ; ReadLn (Month1) ;
    : Write ('Enter today''s day: ') ; ReadLn (Day1) ;
    :
    : BirthDay := Julian (Year0, Month0, Day0) ;
    : Today := Julian (Year1, Month1, Day1) ;
    :
    : WriteLn (Today :10) ;
    : WriteLn (Birthday:10) ;
    :
    : WriteLn ('The person is ', Today - BirthDay, ' days old.')
    : end.
    : [/code]:
    :

    When I run it I have Runtime Error.
  • : : : Hi everybody!
    : : :
    : : : I want to make a program in pascal that calculates the number of
    : : : days of a person. The information that is written from the keyboard
    : : : is the date of birth and the actual day. And i must calculate the
    : : : number of days between this period. Please help me if you can.
    : : : Thanks!
    : : :
    : : I've written this kind of program before. Trust me, the best
    : : solultion is to write a function that will take a year, month, and
    : : day as input and return a Julian date. You can then just subtract
    : : the earlier Julian date from the later Julian date.
    : :
    : : In computer programming a Julian date is the number of days since
    : : the beginning of the year (Jan 1 = 1). For our purposes we need to
    : : define a Julian date as the number of days since some arbitrary
    : : date, say Jan 1 of the year zero. What I lay our here is based on
    : : the Gregorian calendar, which has been in use since the 16th
    : : century. Dates before that based on the Julian calendar may or may
    : : not give correct results.
    : :
    : : Trust me, this approach is ultimately simpler than trying to
    : : subtract one date from another, where you may have to borrow days
    : : from the previous month, which means you have to determe how many
    : : days were in the previous month, and borrowing months from the
    : : privious year which may be a leap year. It's a mess.
    : :
    : : [code]: :
    : : Program Days ;
    : :
    : : Function Julian (Year: Word ; Month, Day : Byte) : LongInt ;
    : :
    : : Function IsLeap (Year : LongInt) : Boolean ;
    : : {
    : : a year is a leap year IF it's divisible by 4
    : : UNLESS it's also divisible by 100, then it's
    : : a leap year ONLY if it divisible by 400
    : : }
    : : begin
    : : if Year DIV 4 = 0 then begin
    : : if Year DIV 100 = 0 then begin
    : : if Year DIV 400 = 0 then
    : : IsLeap := TRUE
    : : else
    : : IsLeap := FALSE
    : : end
    : : else
    : : IsLeap := TRUE
    : : end
    : : else
    : : IsLeap := FALSE
    : : end ;
    : :
    : : Function DaysPriorToThisYear (Year : LongInt) : LongInt ;
    : :
    : : Var
    : : i, Count : LongInt ;
    : :
    : : begin
    : : Count := 0 ;
    : :
    : : for i := 1 to Year - 1 do
    : : if IsLeap(i) then
    : : Count := Count + 366
    : : else
    : : Count := Count + 365 ;
    : :
    : : DaysPriorToThisYear := Count
    : : end ;
    : :
    : : Function DaysPriorToThisMonth (Year, Month : LongInt) : LongInt ;
    : :
    : : CONST
    : : MonthDays : Array [FALSE .. TRUE, 1 .. 12] of LongInt
    : : = ((31,28,31,30,31,30,31,31,30,31,30,31),
    : : (31,29,31,30,31,30,31,31,30,31,30,31)) ;
    : :
    : : Var
    : : i, Count : LongInt ;
    : :
    : : begin
    : : Count := 0 ;
    : :
    : : for i := 1 to Month - 1 do
    : : if IsLeap(Year) then
    : : Count := Count + MonthDays[TRUE, i]
    : : else
    : : Count := Count + MonthDays[FALSE, i] ;
    : :
    : : DaysPriorToThisMonth := Count
    : : end ;
    : :
    : : begin
    : : Julian := DaysPriorToThisYear(Year)
    : : + DaysPriorToThisMonth(Year,Month)
    : : + Day
    : : end ;
    : :
    : : Var
    : : Year0, Year1, Month0, Month1, Day0, Day1, BirthDay, Today : LongInt ;
    : :
    : : begin
    : : Write ('Enter year of birth: ') ; ReadLn (Year0) ;
    : : Write ('Enter month of birth: ') ; ReadLn (Month0) ;
    : : Write ('Enter day of birth: ') ; ReadLn (Day0) ;
    : : WriteLn ;
    : :
    : : Write ('Enter today''s year: ') ; ReadLn (Year1) ;
    : : Write ('Enter today''s month: ') ; ReadLn (Month1) ;
    : : Write ('Enter today''s day: ') ; ReadLn (Day1) ;
    : :
    : : BirthDay := Julian (Year0, Month0, Day0) ;
    : : Today := Julian (Year1, Month1, Day1) ;
    : :
    : : WriteLn (Today :10) ;
    : : WriteLn (Birthday:10) ;
    : :
    : : WriteLn ('The person is ', Today - BirthDay, ' days old.')
    : : end.
    : : [/code]: :
    : :
    :
    : When I run it I have Runtime Error.
    :
    What Runtime Error do you get? What version of Pascal are you using?
  • : : : : Hi everybody!
    : : : :
    : : : : I want to make a program in pascal that calculates the number of
    : : : : days of a person. The information that is written from the keyboard
    : : : : is the date of birth and the actual day. And i must calculate the
    : : : : number of days between this period. Please help me if you can.
    : : : : Thanks!
    : : : :
    : : : I've written this kind of program before. Trust me, the best
    : : : solultion is to write a function that will take a year, month, and
    : : : day as input and return a Julian date. You can then just subtract
    : : : the earlier Julian date from the later Julian date.
    : : :
    : : : In computer programming a Julian date is the number of days since
    : : : the beginning of the year (Jan 1 = 1). For our purposes we need to
    : : : define a Julian date as the number of days since some arbitrary
    : : : date, say Jan 1 of the year zero. What I lay our here is based on
    : : : the Gregorian calendar, which has been in use since the 16th
    : : : century. Dates before that based on the Julian calendar may or may
    : : : not give correct results.
    : : :
    : : : Trust me, this approach is ultimately simpler than trying to
    : : : subtract one date from another, where you may have to borrow days
    : : : from the previous month, which means you have to determe how many
    : : : days were in the previous month, and borrowing months from the
    : : : privious year which may be a leap year. It's a mess.
    : : :
    : : : [code]: : :
    : : : Program Days ;
    : : :
    : : : Function Julian (Year: Word ; Month, Day : Byte) : LongInt ;
    : : :
    : : : Function IsLeap (Year : LongInt) : Boolean ;
    : : : {
    : : : a year is a leap year IF it's divisible by 4
    : : : UNLESS it's also divisible by 100, then it's
    : : : a leap year ONLY if it divisible by 400
    : : : }
    : : : begin
    : : : if Year DIV 4 = 0 then begin
    : : : if Year DIV 100 = 0 then begin
    : : : if Year DIV 400 = 0 then
    : : : IsLeap := TRUE
    : : : else
    : : : IsLeap := FALSE
    : : : end
    : : : else
    : : : IsLeap := TRUE
    : : : end
    : : : else
    : : : IsLeap := FALSE
    : : : end ;
    : : :
    : : : Function DaysPriorToThisYear (Year : LongInt) : LongInt ;
    : : :
    : : : Var
    : : : i, Count : LongInt ;
    : : :
    : : : begin
    : : : Count := 0 ;
    : : :
    : : : for i := 1 to Year - 1 do
    : : : if IsLeap(i) then
    : : : Count := Count + 366
    : : : else
    : : : Count := Count + 365 ;
    : : :
    : : : DaysPriorToThisYear := Count
    : : : end ;
    : : :
    : : : Function DaysPriorToThisMonth (Year, Month : LongInt) : LongInt ;
    : : :
    : : : CONST
    : : : MonthDays : Array [FALSE .. TRUE, 1 .. 12] of LongInt
    : : : = ((31,28,31,30,31,30,31,31,30,31,30,31),
    : : : (31,29,31,30,31,30,31,31,30,31,30,31)) ;
    : : :
    : : : Var
    : : : i, Count : LongInt ;
    : : :
    : : : begin
    : : : Count := 0 ;
    : : :
    : : : for i := 1 to Month - 1 do
    : : : if IsLeap(Year) then
    : : : Count := Count + MonthDays[TRUE, i]
    : : : else
    : : : Count := Count + MonthDays[FALSE, i] ;
    : : :
    : : : DaysPriorToThisMonth := Count
    : : : end ;
    : : :
    : : : begin
    : : : Julian := DaysPriorToThisYear(Year)
    : : : + DaysPriorToThisMonth(Year,Month)
    : : : + Day
    : : : end ;
    : : :
    : : : Var
    : : : Year0, Year1, Month0, Month1, Day0, Day1, BirthDay, Today : LongInt ;
    : : :
    : : : begin
    : : : Write ('Enter year of birth: ') ; ReadLn (Year0) ;
    : : : Write ('Enter month of birth: ') ; ReadLn (Month0) ;
    : : : Write ('Enter day of birth: ') ; ReadLn (Day0) ;
    : : : WriteLn ;
    : : :
    : : : Write ('Enter today''s year: ') ; ReadLn (Year1) ;
    : : : Write ('Enter today''s month: ') ; ReadLn (Month1) ;
    : : : Write ('Enter today''s day: ') ; ReadLn (Day1) ;
    : : :
    : : : BirthDay := Julian (Year0, Month0, Day0) ;
    : : : Today := Julian (Year1, Month1, Day1) ;
    : : :
    : : : WriteLn (Today :10) ;
    : : : WriteLn (Birthday:10) ;
    : : :
    : : : WriteLn ('The person is ', Today - BirthDay, ' days old.')
    : : : end.
    : : : [/code]: : :
    : : :
    : :
    : : When I run it I have Runtime Error.
    : :
    : What Runtime Error do you get? What version of Pascal are you using?
    :

    I had figured out how to make this program. Now i made it and it works. I didn't use the julian date. You're conversion in julian date is interesting, but i calculated the number of the days of a person in this way: A+B+C, where A is the number of days from the birthday to the and of the birth year, B is the number of days from the birthyear+1 to thisyear-1, and C is the number of days from the first day of thisyear to thisday.
  • : : : : Hi everybody!
    : : : :
    : : : : I want to make a program in pascal that calculates the number of
    : : : : days of a person. The information that is written from the keyboard
    : : : : is the date of birth and the actual day. And i must calculate the
    : : : : number of days between this period. Please help me if you can.
    : : : : Thanks!
    : : : :
    : : : I've written this kind of program before. Trust me, the best
    : : : solultion is to write a function that will take a year, month, and
    : : : day as input and return a Julian date. You can then just subtract
    : : : the earlier Julian date from the later Julian date.
    : : :
    : : : In computer programming a Julian date is the number of days since
    : : : the beginning of the year (Jan 1 = 1). For our purposes we need to
    : : : define a Julian date as the number of days since some arbitrary
    : : : date, say Jan 1 of the year zero. What I lay our here is based on
    : : : the Gregorian calendar, which has been in use since the 16th
    : : : century. Dates before that based on the Julian calendar may or may
    : : : not give correct results.
    : : :
    : : : Trust me, this approach is ultimately simpler than trying to
    : : : subtract one date from another, where you may have to borrow days
    : : : from the previous month, which means you have to determe how many
    : : : days were in the previous month, and borrowing months from the
    : : : privious year which may be a leap year. It's a mess.
    : : :
    : : : [code]: : :
    : : : Program Days ;
    : : :
    : : : Function Julian (Year: Word ; Month, Day : Byte) : LongInt ;
    : : :
    : : : Function IsLeap (Year : LongInt) : Boolean ;
    : : : {
    : : : a year is a leap year IF it's divisible by 4
    : : : UNLESS it's also divisible by 100, then it's
    : : : a leap year ONLY if it divisible by 400
    : : : }
    : : : begin
    : : : if Year DIV 4 = 0 then begin
    : : : if Year DIV 100 = 0 then begin
    : : : if Year DIV 400 = 0 then
    : : : IsLeap := TRUE
    : : : else
    : : : IsLeap := FALSE
    : : : end
    : : : else
    : : : IsLeap := TRUE
    : : : end
    : : : else
    : : : IsLeap := FALSE
    : : : end ;
    : : :
    : : : Function DaysPriorToThisYear (Year : LongInt) : LongInt ;
    : : :
    : : : Var
    : : : i, Count : LongInt ;
    : : :
    : : : begin
    : : : Count := 0 ;
    : : :
    : : : for i := 1 to Year - 1 do
    : : : if IsLeap(i) then
    : : : Count := Count + 366
    : : : else
    : : : Count := Count + 365 ;
    : : :
    : : : DaysPriorToThisYear := Count
    : : : end ;
    : : :
    : : : Function DaysPriorToThisMonth (Year, Month : LongInt) : LongInt ;
    : : :
    : : : CONST
    : : : MonthDays : Array [FALSE .. TRUE, 1 .. 12] of LongInt
    : : : = ((31,28,31,30,31,30,31,31,30,31,30,31),
    : : : (31,29,31,30,31,30,31,31,30,31,30,31)) ;
    : : :
    : : : Var
    : : : i, Count : LongInt ;
    : : :
    : : : begin
    : : : Count := 0 ;
    : : :
    : : : for i := 1 to Month - 1 do
    : : : if IsLeap(Year) then
    : : : Count := Count + MonthDays[TRUE, i]
    : : : else
    : : : Count := Count + MonthDays[FALSE, i] ;
    : : :
    : : : DaysPriorToThisMonth := Count
    : : : end ;
    : : :
    : : : begin
    : : : Julian := DaysPriorToThisYear(Year)
    : : : + DaysPriorToThisMonth(Year,Month)
    : : : + Day
    : : : end ;
    : : :
    : : : Var
    : : : Year0, Year1, Month0, Month1, Day0, Day1, BirthDay, Today : LongInt ;
    : : :
    : : : begin
    : : : Write ('Enter year of birth: ') ; ReadLn (Year0) ;
    : : : Write ('Enter month of birth: ') ; ReadLn (Month0) ;
    : : : Write ('Enter day of birth: ') ; ReadLn (Day0) ;
    : : : WriteLn ;
    : : :
    : : : Write ('Enter today''s year: ') ; ReadLn (Year1) ;
    : : : Write ('Enter today''s month: ') ; ReadLn (Month1) ;
    : : : Write ('Enter today''s day: ') ; ReadLn (Day1) ;
    : : :
    : : : BirthDay := Julian (Year0, Month0, Day0) ;
    : : : Today := Julian (Year1, Month1, Day1) ;
    : : :
    : : : WriteLn (Today :10) ;
    : : : WriteLn (Birthday:10) ;
    : : :
    : : : WriteLn ('The person is ', Today - BirthDay, ' days old.')
    : : : end.
    : : : [/code]: : :
    : : :
    : :
    : : When I run it I have Runtime Error.
    : :
    : What Runtime Error do you get? What version of Pascal are you using?
    :

    The error is:
    Runtime error 105 at 0001:0253. The compilation works though.
    And version? you mean compiler? if yes, then its Turbo Pascal for Windows 7. I think it's kinda old, right?
  • : : : : : Hi everybody!
    : : : : :
    : : : : : I want to make a program in pascal that calculates the number of
    : : : : : days of a person. The information that is written from the keyboard
    : : : : : is the date of birth and the actual day. And i must calculate the
    : : : : : number of days between this period. Please help me if you can.
    : : : : : Thanks!
    : : : : :
    : : : : I've written this kind of program before. Trust me, the best
    : : : : solultion is to write a function that will take a year, month, and
    : : : : day as input and return a Julian date. You can then just subtract
    : : : : the earlier Julian date from the later Julian date.
    : : : :
    : : : : In computer programming a Julian date is the number of days since
    : : : : the beginning of the year (Jan 1 = 1). For our purposes we need to
    : : : : define a Julian date as the number of days since some arbitrary
    : : : : date, say Jan 1 of the year zero. What I lay our here is based on
    : : : : the Gregorian calendar, which has been in use since the 16th
    : : : : century. Dates before that based on the Julian calendar may or may
    : : : : not give correct results.
    : : : :
    : : : : Trust me, this approach is ultimately simpler than trying to
    : : : : subtract one date from another, where you may have to borrow days
    : : : : from the previous month, which means you have to determe how many
    : : : : days were in the previous month, and borrowing months from the
    : : : : privious year which may be a leap year. It's a mess.
    : : : :
    : : : : [code]: : : :
    : : : : Program Days ;
    : : : :
    : : : : Function Julian (Year: Word ; Month, Day : Byte) : LongInt ;
    : : : :
    : : : : Function IsLeap (Year : LongInt) : Boolean ;
    : : : : {
    : : : : a year is a leap year IF it's divisible by 4
    : : : : UNLESS it's also divisible by 100, then it's
    : : : : a leap year ONLY if it divisible by 400
    : : : : }
    : : : : begin
    : : : : if Year DIV 4 = 0 then begin
    : : : : if Year DIV 100 = 0 then begin
    : : : : if Year DIV 400 = 0 then
    : : : : IsLeap := TRUE
    : : : : else
    : : : : IsLeap := FALSE
    : : : : end
    : : : : else
    : : : : IsLeap := TRUE
    : : : : end
    : : : : else
    : : : : IsLeap := FALSE
    : : : : end ;
    : : : :
    : : : : Function DaysPriorToThisYear (Year : LongInt) : LongInt ;
    : : : :
    : : : : Var
    : : : : i, Count : LongInt ;
    : : : :
    : : : : begin
    : : : : Count := 0 ;
    : : : :
    : : : : for i := 1 to Year - 1 do
    : : : : if IsLeap(i) then
    : : : : Count := Count + 366
    : : : : else
    : : : : Count := Count + 365 ;
    : : : :
    : : : : DaysPriorToThisYear := Count
    : : : : end ;
    : : : :
    : : : : Function DaysPriorToThisMonth (Year, Month : LongInt) : LongInt ;
    : : : :
    : : : : CONST
    : : : : MonthDays : Array [FALSE .. TRUE, 1 .. 12] of LongInt
    : : : : = ((31,28,31,30,31,30,31,31,30,31,30,31),
    : : : : (31,29,31,30,31,30,31,31,30,31,30,31)) ;
    : : : :
    : : : : Var
    : : : : i, Count : LongInt ;
    : : : :
    : : : : begin
    : : : : Count := 0 ;
    : : : :
    : : : : for i := 1 to Month - 1 do
    : : : : if IsLeap(Year) then
    : : : : Count := Count + MonthDays[TRUE, i]
    : : : : else
    : : : : Count := Count + MonthDays[FALSE, i] ;
    : : : :
    : : : : DaysPriorToThisMonth := Count
    : : : : end ;
    : : : :
    : : : : begin
    : : : : Julian := DaysPriorToThisYear(Year)
    : : : : + DaysPriorToThisMonth(Year,Month)
    : : : : + Day
    : : : : end ;
    : : : :
    : : : : Var
    : : : : Year0, Year1, Month0, Month1, Day0, Day1, BirthDay, Today : LongInt ;
    : : : :
    : : : : begin
    : : : : Write ('Enter year of birth: ') ; ReadLn (Year0) ;
    : : : : Write ('Enter month of birth: ') ; ReadLn (Month0) ;
    : : : : Write ('Enter day of birth: ') ; ReadLn (Day0) ;
    : : : : WriteLn ;
    : : : :
    : : : : Write ('Enter today''s year: ') ; ReadLn (Year1) ;
    : : : : Write ('Enter today''s month: ') ; ReadLn (Month1) ;
    : : : : Write ('Enter today''s day: ') ; ReadLn (Day1) ;
    : : : :
    : : : : BirthDay := Julian (Year0, Month0, Day0) ;
    : : : : Today := Julian (Year1, Month1, Day1) ;
    : : : :
    : : : : WriteLn (Today :10) ;
    : : : : WriteLn (Birthday:10) ;
    : : : :
    : : : : WriteLn ('The person is ', Today - BirthDay, ' days old.')
    : : : : end.
    : : : : [/code]: : : :
    : : : :
    : : :
    : : : When I run it I have Runtime Error.
    : : :
    : : What Runtime Error do you get? What version of Pascal are you using?
    : :
    :
    : The error is:
    : Runtime error 105 at 0001:0253. The compilation works though.
    : And version? you mean compiler? if yes, then its Turbo Pascal for
    : Windows 7. I think it's kinda old, right?
    :
    Runtime error 105 is "file not open for output." The file in question is "output."

    Try including the line "Uses WinCrt ;" right after the program line, thus:
    [code]
    Program Days ;

    Uses
    WinCrt ;
    [/code]
    I don't have Turbo Pascal for Windows 7 but I do have some of its documentation. It says that TPW7 does not have [b]input[/b] and [b]output[/b] in its standard unit. Simply including the [b]Uses[/b] statement may be enough. If not, try including a statement "ReSet (output) ;"
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories