You are Here: Home

# Pascal programming watch

1. 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.');
while (k < 1) or (k > 31) do
begin
writeln ('Wrong!!!');
end;
writeln('Enter the chosen month.(as a digit)') ;

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

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

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);

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

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

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

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

writeln (day5 div 7);

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

end.
2. Sorry i don't know pascal, but your leaving your cwk a bit late? The write up takes longer than i thought
3. (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?
4. I'm guessing something to do with a booking system for the AQA cwk.
5. 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
6. 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 ....
7. What is it giving you when you enter all these details?
8. 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.
9. 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!
10. 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');
writeln('Enter the month');
writeln('Enter the 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;
end.```
11. (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');
writeln('Enter the month');
writeln('Enter the 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;
end.```
i used delphi and functions from the dateutils unit so i cant really help here, sorry
12. 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:
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.');
while(k<1)or(k>31)do
begin
writeln('Wrong!!!');
end;
writeln('Enter the chosen month.(as a digit)') ;
while(m<1)or(m>12)do
begin
writeln('Wrong!!!');
end;
writeln('Enter the chosen year.') ;
while(Y<1582)or(Y>4903)do
begin
writeln('Wrong!!!');
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]);
end.
Lol

TSR Support Team

We have a brilliant team of more than 60 Support Team members looking after discussions on The Student Room, helping to make it a fun, safe and useful place to hang out.

This forum is supported by:
Updated: April 18, 2006
Today on TSR

### Edexcel C2 Core Unofficial Markscheme!

Find out how you've done here

Poll
Useful resources