Anna10
Badges: 2
#1
Report Thread starter 13 years ago
#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.');
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.
0
reply
Swinely
Badges: 2
Rep:
?
#2
Report 13 years ago
#2
Sorry i don't know pascal, but your leaving your cwk a bit late? The write up takes longer than i thought
0
reply
slugonamission
Badges: 0
Rep:
?
#3
Report 13 years ago
#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?
0
reply
Swinely
Badges: 2
Rep:
?
#4
Report 13 years ago
#4
I'm guessing something to do with a booking system for the AQA cwk.
0
reply
Imster
Badges: 8
Rep:
?
#5
Report 13 years ago
#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 :p:
0
reply
Anna10
Badges: 2
#6
Report Thread starter 13 years ago
#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 ....
0
reply
Imster
Badges: 8
Rep:
?
#7
Report 13 years ago
#7
What is it giving you when you enter all these details?
0
reply
Anna10
Badges: 2
#8
Report Thread starter 13 years ago
#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.
0
reply
Oddball
Badges: 11
Rep:
?
#9
Report 13 years ago
#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!
0
reply
Kry1010
Badges: 0
Rep:
?
#10
Report 13 years ago
#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');
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.
0
reply
slugonamission
Badges: 0
Rep:
?
#11
Report 13 years ago
#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');
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
0
reply
Alexandr
Badges: 0
Rep:
?
#12
Report 13 years ago
#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:
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
0
reply
X

Quick Reply

Attached files
Write a reply...
Reply
new posts
Back
to top
Latest
My Feed

See more of what you like on
The Student Room

You can personalise what you see on TSR. Tell us a little about yourself to get started.

Personalise

- Have you considered distance learning for any of your qualifications?

Yes! I'm on a distance learning course right now (9)
7.96%
Yes, I've thought about it but haven't signed up yet (12)
10.62%
No, but maybe I will look into it (28)
24.78%
No and I wouldn't consider it (64)
56.64%

Watched Threads

View All