birthday and corresponding week day

I want to write a program to determine the day of the week a person was born,given his or her birth date,using the following steps to find the day of the week corresponding to any date in this century.
 (a.) Divide the last two digits of the birth year by 4. Put the qoutient (ignoring the remainder)in Total. For example,if the person was born in 1983,divide 83 by 4 and store 20 in Total.
 (b.) Add the last two digits of the birth year to Total.
 (c.) Add the last two digits of the date of birth to Total.
 (d.) Using the following table,find the "month number" and add it to Total:
   January = 1             July = 0
   February = 4            August = 3
   March = 4               September = 6
   April = 0               October = 1
   May = 2                 November = 4
   June = 5                December = 6
 (e.) If the year is a leap year and if the month is either January or February then subtract 1 from the Total.
 (f.) Find the remainder when Total is divided by 7. Look up the remainder in the following table to determine the day of the week the person was born. Of course the procedure cannot be used if the person's date of birth is before 1900.
 1= Sunday ,2= Monday ,3 = Tuesday,
 4= Wednesday , 5 = Thursday, 6 = Friday, 0 = Saturday.

A typical line of date is 5-15 78 where the first entry (5-15) represents the birthdate (May 15) and the second entry represents the birth year. An appropriate errror message should be printed if a person's year of birth is before 1900.
   This is a pascal program.
triffid1962Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ozoCommented:
Do you have a question?
0
BatalfCommented:
Are you asking for the the source code of this program?
0
triffid1962Author Commented:
I'm trying to write the program but I'm totally lost.I have no idea what I'm doing.
0
Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

_lychee_Commented:
well... u can write a function that returns the day of the week first (that uses the algorithm u stated), and then write ur input and output around it...
0
triffid1962Author Commented:
I'm completely new at this I've been trying to figure out what to do for two days. I wrote to you guys in desparation.
0
BatalfCommented:
Hi

Here are a suggestion of a procedure which could solve your problem.
Note : I have not typed down the whole program, just the code which finds the day of week.

var{global variables}
      year : string[10];
{the user must type in his
      birthday like this mm-dd-yyyy, ex : 05-15-1983}

      var1 : string[5];
      var2,var3, var4 : integer;
      code : integer;

      total : integer;
      day : string[15];


procedure getdate;
begin
      var1:= mid(year, 9, 2);  {not quite sure about the syntax here. In
                        Dephi, we use the copy-command(var1:=copy(year,9,2).
                        The point here is to get the two last digits in the year}

      val(var1, var2, code); {convert the textvar "var1" to an integer value}

      total := trunc(var2/4); {returning the value 20 if var2 = 83)

      total:=total + var2; {add the last two digits of birthdate to the total}

      var1:= mid(year,4,2); {add the last two digits of the dato of birth to total}
      val(var1,var2, code);
      total:=total + var2;

      {find the month number ->}
      case var2 of
      1      :      var3:=1;
      2      :      var3:=4;
      3      :      var3:=4;
      4      :      var3:=0;
      5      :      var3:=2;
      6      :      var3:=5;
      7      :      var3:=0;
      8      :      var3:=3;
      9      :      var3:=6;
      10      :      var3:=1;
      11      :      var3:=4;
      12      :      var3:=6;
      end;

      total := total + var3; {adding "month number" to total}

      {if the year is a leap}
      var1:=mid(year,7,4)
      val(var1, var3 , code);
      if (mod(var3,4)=0) and (var2<3) then dec(total)
      {the mod-command returns 0 if it's a leap year. All years which returns 0 when
      it's divided by 4 is a leap year}

      {divide the total by 7 and returning the reminder}

      var3:=mod(total,7); {The mod-function should return the reminder here, when
                        total is divided by 7. An other way to do it is like this :
                        var3:=total-trunc(total/7) }

      case var3 of
      1      :       day := 'Sunday';
      2      :      day := 'Monday';
      3      :       day := 'Tuesday';
      4      :      day := 'Wednesday';
      5      :      day := 'Thursday';
      6      :      day := 'Friday';
      7      :      day := 'Saturday';
      end;

end;


      


      

      

      
      
            

      


      
      
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
vikiingCommented:
Some comments:

1) >> An other way to do it is like this :
      var3:=total-trunc(total/7) }

   The correct way should be:
      var3:=(total-trunc(total/7)) * 7

   But, due to rounding problems, the best way is simply:
      var3:= total mod 7;


2) >>case var3 of
     7 : day := 'Saturday';

   The reminder of a division by 7, can never be 7... :)
   As Triffid said, Saturday is for reminder = 0.


3) >>All years which returns 0 when it's divided by 4 is a
   leap year

   That's NOT true for 1900, which wasn't a leap year.
0
BatalfCommented:
There could be some minor errors in my code. I haven't tried it myself.

I haven't Pascal installed on the PC I'm working on at the moment.

Please let me know if something isn't clear. I would suggest corrections.

Regards
Batalf
0
HypoCommented:
Ahhw, this question is already answered... Damn, I would have answered it if (ironicly) we wouldn't have had a TeleLine malfunction on our lines today... ahh wtf, I'll post my program anyway, (nevermind the points)

I made this program during a bet with a pascal course friend last year. The goal was to get as few lines as possible... and I won :) I went down to below 20 lines of code... And it can handle any year above year 0, e.g. It works (as well as I know) perfectly for years such as 1223, 6589 as well as years in the 20th and 21st century.

(This is not how the code looked when I won the bet with it...)

The things that doesn't match your criteria triffid is that you must enter the date in this order, (YYYY MM DD) 1999 11 22, the result should be Monday, and that this one works for any century after year 0. But WTH. Batalf has already answered your question anyway.

Program DayOfDate;

uses crt;

const
     Tab1 : array[0..1,0..11] of byte = ((1,4,4,0,2,5,0,3,6,1,4,6),
                                          (0,3,4,0,2,5,0,3,6,1,4,6));
     Korr : array[0..3] of byte = (6,4,2,0);
     WDay : array[0..6] of string = ('Sunday','Monday','Tuesday','Wednesday',
                                      'Thursday','Friday','Saturday');
     WMon : array[0..11] of string = ('January','February','March','April',
                                      'May','June','July','August','September',
                                      'October','November','December');

var  Year,Dummy,Month,Day : word;

Function CheckYear : boolean; { is true if the year var. is a leap year }
var _Dummy : boolean;
begin
 _Dummy := (year mod 100 and 3) = 0;
 If Year mod 100 = 0 then _Dummy := (year Div 100 and 3) = 0;
 CheckYear := _Dummy;
end;

Function RetEnd(V : word) : string;
Const RS : array[1..4] of string = ('st, ','nd, ','rd, ','th, ');
begin
  if (V <= 4) and (V > 0) then RetEnd := Rs[V] else RetEnd := Rs[4];
end;

begin
  Write('Enter date : '); { date should be entered in "YYYY MM DD" style }
  Readln(year,month,day);
  Dummy := Year mod 100;
  Dummy := Dummy + (Dummy shr 2) + tab1[byte(CheckYear),month-1] + day + Korr[year div 100 and 3];
  Writeln(WMon[month-1],' ',day,RetEnd(day),year,' is a ',Wday[(Dummy-1) mod 7]);
  Readkey;
end.
0
vikiingCommented:
Here's how you can save a couple of lines: work directly with function name, without using an intermediary variable (what for?):

Function CheckYear : boolean;
begin
 CheckYear := (year mod 100 and 3) = 0;
 If Year mod 100 = 0 then
        CheckYear := (year Div 100 and 3) = 0;
end;


BTW, I have the algorithm to find the day of Easter Sunday... Incredibly, there exists !!!  :)
0
My name is MudSystems EngineerCommented:
>>I want to write a program to determine... Blah blah blah...

What's stoping you... Is too difficult??? well it doesn't say so in the points...
0
vikiingCommented:
It's always the same: someone gets an answer quickly and promptly. But, when it's time to pay, things are not the same... :(
0
vikiingCommented:
Clap !! for Triffid...

:)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Pascal

From novice to tech pro — start learning today.