Turn on thread page Beta
    • Thread Starter
    Offline

    2
    ReputationRep:
    Does anyone know how to programme in Pascal ... it is what i am using for my Computing coursework - The Villiage Hall, Unit 3.

    I have hardly started i am getting worried now i want to programme but i done no how to fix this as it does not give me the correct day:

    program newannascalculator;

    var counter, dayfinal :integer;
    k, D, C,m, month1 :integer;
    day, day1, day2, day3, day4, day5 :integer;
    dayofweek : array [0..6] of String;
    month : array [1..12] of String;

    //f = k + [(13*m-1)/5] + D + [D/4] + [C/4] - 2*C.

    begin
    dayofweek[0] := 'Sunday';
    dayofweek[1] := 'Monday';
    dayofweek[2] := 'Tuesday';
    dayofweek[3] := 'Wednesday';
    dayofweek[4] := 'Thursday';
    dayofweek[5] := 'Friday';
    dayofweek[6] := 'Saturday';

    month[1]:= 'march';
    month[2]:= 'april';
    month[3]:= 'may';
    month[4]:= 'june';
    month[5]:= 'july';
    month[6]:= 'august';
    month[7]:= 'september';
    month[8]:= 'october';
    month[9]:= 'november' ;
    month[10]:= 'december';
    month[11]:= 'january' ;
    month[12]:= 'february';

    writeln('Enter the chosen date of the month.');
    readln (k );
    while (k < 1) or (k > 31) do
    begin
    writeln ('Wrong!!!');
    readln (k);
    end;
    writeln('Enter the chosen month.(as a digit)') ;
    readln (m) ;

    writeln('Enter the first two digits chosen year.') ;
    readln (C);

    writeln('Enter the last two digits of the chosen year.');
    readln (D);

    counter :=0;

    //f = k + [(13*m-1)/5] + D + [D/4] + [C/4] - 2*C.

    if m - 1 = 0 then m:= 12 else m := m-1 ;

    day := (13*(m))div 5;
    writeln (day);
    readln ;

    day1 :=k + day ;
    writeln (day1);
    readln ;

    day2 := day1 + D;
    writeln (day2);
    readln ;

    day3 := day2 + D div 4;
    writeln (day3);
    readln ;

    day4 := day3 + C div 4 ;
    writeln (day4);
    readln ;
    day5 := day4 - 2*C;
    writeln (day5);
    readln ;

    writeln (day5 div 7);
    readln ;

    dayfinal := day5 mod 7;
    writeln (dayfinal);
    readln ;
    //f - 7*[f/7]
    if dayfinal <0
    then dayfinal := dayfinal-7*(dayfinal div 7) ;
    writeln (dayfinal);
    readln ;
    // repeat
    //dayofweek :=dayfinal + dayofweek[counter];
    writeln (dayofweek[dayfinal]);
    readln;
    //counter :=counter+1;
    //until counter=dayfinal;

    end.
    Offline

    2
    ReputationRep:
    Sorry i don't know pascal, but your leaving your cwk a bit late? The write up takes longer than i thought
    Offline

    0
    ReputationRep:
    (Original post by Swinely)
    Sorry i don't know pascal, but your leaving your cwk a bit late? The write up takes longer than i thought
    what is that code actually supposed to do?
    Offline

    2
    ReputationRep:
    I'm guessing something to do with a booking system for the AQA cwk.
    Offline

    0
    ReputationRep:
    I could follow that...But telling what's wrong with it I wouldn't be able to do, what do you input when you run it and what do you get and what are you meant to get?

    I did my AS project in PHP lol, good fun it was too :p:
    • Thread Starter
    Offline

    2
    ReputationRep:
    I know i am leaving it late. That is why i am here trying to find help!

    But what you input is: the date, the month, the first two digits of the year, and then the last two digits. (all in numbers)

    It is then meant to give me what day of the week is it for that input digits!!

    The way the arrys work i found on a internet site - i have had someone at school looking at it but they are baffelled as to why it doesnt give the correct day.

    Hope this helps ....
    Offline

    0
    ReputationRep:
    What is it giving you when you enter all these details?
    • Thread Starter
    Offline

    2
    ReputationRep:
    It gives me the previous day or the day after what the actual answer is!!
    eg: if i wanted the 4th Jan 2006 which was a Wednesday
    It gives me tuesday.
    Offline

    11
    ReputationRep:
    Can you find a rule as to why? I mean, computers are logical, and they are only doing what they are told. Can't tell you what your problem is, but try writing up a test plan and writing what you find, and try to find patterns from your findings.

    Pascal isn't my native, C++ is. Love it to bits. Hate Pascal's guts!
    Offline

    0
    ReputationRep:
    It's been a while since I've done any Pascal, but I tried to compile your code and it wouldn't...is it a requirement of the coursework to use that formula you're using? If not then why don't you use Zeller's congruence...it makes what you're trying to accomplish much simpler.

    I put together a quick and dirty program (which seems to work) that does what you want using Zeller's congruence...in case you're allowed to use a different formula

    Code:
    program DayPredictor;
    
    var a, b, c, z, day, month, year:integer;
    
    begin
    writeln('Enter the year');
    readln(year);
    writeln('Enter the month');
    readln(month);
    writeln('Enter the day');
    readln(day);
    
    if (month <=2) then
    begin
      a := month + 10;
      b := (year-1) mod 100;
      c := (year-1) div 100;
    end
    
    else
      begin
       a := month - 2;
       b := year mod 100;
       c := year div 100;
       end;
    
    z := (700 + (26 * a - 2) div 10 + day + b + (b div 4) + (c div 4) - 2 * c) mod 7;
    
    case z OF
    
    0: writeln('Sunday');
    1: writeln('Monday');
    2: writeln('Tuesday');
    3: writeln('Wednesday');
    4: writeln('Thursday');
    5: writeln('Friday');
    6: writeln('Saturday');
    end;
    readln;
    end.
    Offline

    0
    ReputationRep:
    (Original post by Kry1010)
    It's been a while since I've done any Pascal, but I tried to compile your code and it wouldn't...is it a requirement of the coursework to use that formula you're using? If not then why don't you use Zeller's congruence...it makes what you're trying to accomplish much simpler.

    I put together a quick and dirty program (which seems to work) that does what you want using Zeller's congruence...in case you're allowed to use a different formula

    Code:
    program DayPredictor;
    
    var a, b, c, z, day, month, year:integer;
    
    begin
    writeln('Enter the year');
    readln(year);
    writeln('Enter the month');
    readln(month);
    writeln('Enter the day');
    readln(day);
    
    if (month <=2) then
    begin
      a := month + 10;
      b := (year-1) mod 100;
      c := (year-1) div 100;
    end
    
    else
      begin
       a := month - 2;
       b := year mod 100;
       c := year div 100;
       end;
    
    z := (700 + (26 * a - 2) div 10 + day + b + (b div 4) + (c div 4) - 2 * c) mod 7;
    
    case z OF
    
    0: writeln('Sunday');
    1: writeln('Monday');
    2: writeln('Tuesday');
    3: writeln('Wednesday');
    4: writeln('Thursday');
    5: writeln('Friday');
    6: writeln('Saturday');
    end;
    readln;
    end.
    i used delphi and functions from the dateutils unit so i cant really help here, sorry
    Offline

    0
    ReputationRep:
    It isn't hard!
    Your mistake: if month is january or february then you must make the year as the previous year.
    This code works correctly for years between 1582 and 4903 - new Grigorian's style.
    Worked code:
    program newalexnadrscalculator;
    var
    y,k,d,c,m,day:integer;
    dayofweek:array[0..6] of String;
    month:array[1..12] of String;
    begin
    dayofweek[0]:='Sunday';
    dayofweek[1]:='Monday';
    dayofweek[2]:='Tuesday';
    dayofweek[3]:='Wednesday';
    dayofweek[4]:='Thursday';
    dayofweek[5]:='Friday';
    dayofweek[6]:='Saturday';
    month[1]:='march';
    month[2]:='april';
    month[3]:='may';
    month[4]:='june';
    month[5]:='july';
    month[6]:='august';
    month[7]:='september';
    month[8]:='october';
    month[9]:='november' ;
    month[10]:='december';
    month[11]:='january' ;
    month[12]:='february';
    writeln('Enter the chosen date of the month.');
    readln(k);
    while(k<1)or(k>31)do
    begin
    writeln('Wrong!!!');
    readln(k);
    end;
    writeln('Enter the chosen month.(as a digit)') ;
    readln(m);
    while(m<1)or(m>12)do
    begin
    writeln('Wrong!!!');
    readln(m);
    end;
    writeln('Enter the chosen year.') ;
    readln(Y);
    while(Y<1582)or(Y>4903)do
    begin
    writeln('Wrong!!!');
    readln(Y);
    end;
    if m>=3 then m:=m-2
    else
    begin
    m:=m+10;
    y:=y-1;
    end;
    c:=y div 100;
    d:=y mod 100;
    day:=(700+k+(13*m-1)div 5+d+d div 4+c div 4-2*c)mod 7;
    writeln (dayofweek[day]);
    readln;
    end.
    Lol
 
 
 
Poll
Do you think parents should charge rent?
Useful resources

The Student Room, Get Revising and Marked by Teachers are trading names of The Student Room Group Ltd.

Register Number: 04666380 (England and Wales), VAT No. 806 8067 22 Registered Office: International House, Queens Road, Brighton, BN1 3XE

Write a reply...
Reply
Hide
Reputation gems: You get these gems as you gain rep from other members for making good contributions and giving helpful advice.