Howdy, Stranger!

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

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Pascal help required for noob

Could someone please help me out with this code which i have been writing using case

I am new to programming and therefore this is probably an easy problem to solve, i have been asked to write a school timetable program which displays which lesson is at a user specified time in the week. Could someone please show me where this is wrong because the selections for monday are being used for every day (this should become clearer when the code is read) Thank You very much for any support you could give to me in solving this problem.

Program CaseDemo;
Uses wincrt;

Var
choice : integer;
choiceMonday : integer;
choiceTuesday : integer;
choiceWednesday : integer;
choiceThursday : integer;
choiceFriday : integer;

Begin
Writeln('Welcome to the Timetable Guru');
Writeln('Please enter which day of the week it is today');
writeln;

Writeln('Monday = 1');
Writeln('Tuesday = 2');
Writeln('Wednesday = 3');
Writeln('Thursday = 4');
Writeln('Friday = 5');
Readln(choice);

writeln;

Case choice of
1: writeln('Monday');
2: writeln('Tuesday');
3: writeln('Wednesday');
4: writeln('Thursday');
5: writeln('Friday');
Else writeln('what day are you talking about? Not recognised!');
End; {end of case statement}

writeln;
writeln;

If choice = 1
then writeln ('Choose a Lesson on Monday');

Writeln('Lesson One = 1');
Writeln('Lesson Two = 2');
Writeln('Lesson Three = 3');
Writeln('Lesson Four = 4');
Writeln('Lesson Five = 5');
Readln(ChoiceMonday);
writeln;

Case ChoiceMonday of 1: writeln('Lesson One on Monday is Computing');
2: writeln('Lesson Two on Monday is Computing');
3: writeln('Lesson Three on Monday is a free Period');
4: writeln('Lesson Four on Monday is a free Period');
5: writeln('Lesson Five on Monday is a free Period');
Else writeln('There are only 5 Lessons a day, you have made a mistake!');
End;
End.

writeln;
writeln;

If choice = 2
then writeln ('Choose a lesson on Tuesday');

Writeln('Lesson One = 1');
Writeln('Lesson Two = 2');
Writeln('Lesson Three = 3');
Writeln('Lesson Four = 4');
Writeln('Lesson Five = 5');
Readln(ChoiceTuesday);
writeln;

Case ChoiceTuesday of 1: writeln('Lesson One on Tuesday is Physics');
2: writeln('Lesson Two on Tuesday is Physics');
3: writeln('Lesson Three on Tuesday is Geology');
4: writeln('Lesson Four on Tuesday is Geology');
5: writeln('Lesson Five on Tuesday is Maths');
Else writeln('There are only 5 Lessons a day, you have made a mistake!');
End;
End.

writeln;
writeln;

If choice = 3
then writeln ('Choose a lesson on Wednesday');

Writeln('Lesson One = 1');
Writeln('Lesson Two = 2');
Writeln('Lesson Three = 3');
Writeln('Lesson Four = 4');
Writeln('Lesson Five = 5');
Readln(ChoiceWednesday);
writeln;

Case ChoiceWednesday of 1: writeln('Lesson One on Wednesday is a free Period');
2: writeln('Lesson Two on Wednesday is a free Period');
3: writeln('Lesson Three on Wednesday is Physics');
4: writeln('Lesson Four on Wednesday is Physics');
5: writeln('Lesson Five on Wednesday is Computing');
Else writeln('There are only 5 Lessons a day, you have made a mistake!');
End;
End.

writeln;
writeln;

If choice = 2
then writeln ('Choose a lesson on Thursday');

Writeln('Lesson One = 1');
Writeln('Lesson Two = 2');
Writeln('Lesson Three = 3');
Writeln('Lesson Four = 4');
Writeln('Lesson Five = 5');
Readln(ChoiceThursday);
writeln;

Case ChoiceThursday of 1: writeln('Lesson One on Thursday is Maths');
2: writeln('Lesson Two on Thursday is Maths');
3: writeln('Lesson Three on Thursday is Computing');
4: writeln('Lesson Four on Thursday is Computing');
5: writeln('Lesson Five on Thursday is a free Period');
Else writeln('There are only 5 Lessons a day, you have made a mistake!');
End;
End.

writeln;
writeln;

If choice = 2
then writeln ('Choose a lesson on Friday');
writeln;
Writeln('Lesson One = 1');
Writeln('Lesson Two = 2');
Writeln('Lesson Three = 3');
Writeln('Lesson Four = 4');
Writeln('Lesson Five = 5');
Readln(ChoiceFriday);
writeln;

Case ChoiceFriday of 1: writeln('Lesson One on Friday is Geology');
2: writeln('Lesson Two on Friday is Geology');
3: writeln('Lesson Three on Friday is Maths');
4: writeln('Lesson Four on Friday is Maths');
5: writeln('Lesson Five on Friday is Physics');
Else writeln('There are only 5 Lessons a day, you have made a mistake!');
End;



End.

Comments

  • zibadianzibadian Posts: 6,349Member
    : Could someone please help me out with this code which i have been writing using case
    :
    : I am new to programming and therefore this is probably an easy problem to solve, i have been asked to write a school timetable program which displays which lesson is at a user specified time in the week. Could someone please show me where this is wrong because the selections for monday are being used for every day (this should become clearer when the code is read) Thank You very much for any support you could give to me in solving this problem.
    :
    : Program CaseDemo;
    : Uses wincrt;
    :
    : Var
    : choice : integer;
    : choiceMonday : integer;
    : choiceTuesday : integer;
    : choiceWednesday : integer;
    : choiceThursday : integer;
    : choiceFriday : integer;
    :
    : Begin
    : Writeln('Welcome to the Timetable Guru');
    : Writeln('Please enter which day of the week it is today');
    : writeln;
    :
    : Writeln('Monday = 1');
    : Writeln('Tuesday = 2');
    : Writeln('Wednesday = 3');
    : Writeln('Thursday = 4');
    : Writeln('Friday = 5');
    : Readln(choice);
    :
    : writeln;
    :
    : Case choice of
    : 1: writeln('Monday');
    : 2: writeln('Tuesday');
    : 3: writeln('Wednesday');
    : 4: writeln('Thursday');
    : 5: writeln('Friday');
    : Else writeln('what day are you talking about? Not recognised!');
    : End; {end of case statement}
    :
    : writeln;
    : writeln;
    :
    : If choice = 1
    : then writeln ('Choose a Lesson on Monday');
    :
    : Writeln('Lesson One = 1');
    : Writeln('Lesson Two = 2');
    : Writeln('Lesson Three = 3');
    : Writeln('Lesson Four = 4');
    : Writeln('Lesson Five = 5');
    : Readln(ChoiceMonday);
    : writeln;
    :
    : Case ChoiceMonday of 1: writeln('Lesson One on Monday is Computing');
    : 2: writeln('Lesson Two on Monday is Computing');
    : 3: writeln('Lesson Three on Monday is a free Period');
    : 4: writeln('Lesson Four on Monday is a free Period');
    : 5: writeln('Lesson Five on Monday is a free Period');
    : Else writeln('There are only 5 Lessons a day, you have made a mistake!');
    : End;
    : End.
    :
    : writeln;
    : writeln;
    :
    : If choice = 2
    : then writeln ('Choose a lesson on Tuesday');
    :
    : Writeln('Lesson One = 1');
    : Writeln('Lesson Two = 2');
    : Writeln('Lesson Three = 3');
    : Writeln('Lesson Four = 4');
    : Writeln('Lesson Five = 5');
    : Readln(ChoiceTuesday);
    : writeln;
    :
    : Case ChoiceTuesday of 1: writeln('Lesson One on Tuesday is Physics');
    : 2: writeln('Lesson Two on Tuesday is Physics');
    : 3: writeln('Lesson Three on Tuesday is Geology');
    : 4: writeln('Lesson Four on Tuesday is Geology');
    : 5: writeln('Lesson Five on Tuesday is Maths');
    : Else writeln('There are only 5 Lessons a day, you have made a mistake!');
    : End;
    : End.
    :
    : writeln;
    : writeln;
    :
    : If choice = 3
    : then writeln ('Choose a lesson on Wednesday');
    :
    : Writeln('Lesson One = 1');
    : Writeln('Lesson Two = 2');
    : Writeln('Lesson Three = 3');
    : Writeln('Lesson Four = 4');
    : Writeln('Lesson Five = 5');
    : Readln(ChoiceWednesday);
    : writeln;
    :
    : Case ChoiceWednesday of 1: writeln('Lesson One on Wednesday is a free Period');
    : 2: writeln('Lesson Two on Wednesday is a free Period');
    : 3: writeln('Lesson Three on Wednesday is Physics');
    : 4: writeln('Lesson Four on Wednesday is Physics');
    : 5: writeln('Lesson Five on Wednesday is Computing');
    : Else writeln('There are only 5 Lessons a day, you have made a mistake!');
    : End;
    : End.
    :
    : writeln;
    : writeln;
    :
    : If choice = 2
    : then writeln ('Choose a lesson on Thursday');
    :
    : Writeln('Lesson One = 1');
    : Writeln('Lesson Two = 2');
    : Writeln('Lesson Three = 3');
    : Writeln('Lesson Four = 4');
    : Writeln('Lesson Five = 5');
    : Readln(ChoiceThursday);
    : writeln;
    :
    : Case ChoiceThursday of 1: writeln('Lesson One on Thursday is Maths');
    : 2: writeln('Lesson Two on Thursday is Maths');
    : 3: writeln('Lesson Three on Thursday is Computing');
    : 4: writeln('Lesson Four on Thursday is Computing');
    : 5: writeln('Lesson Five on Thursday is a free Period');
    : Else writeln('There are only 5 Lessons a day, you have made a mistake!');
    : End;
    : End.
    :
    : writeln;
    : writeln;
    :
    : If choice = 2
    : then writeln ('Choose a lesson on Friday');
    : writeln;
    : Writeln('Lesson One = 1');
    : Writeln('Lesson Two = 2');
    : Writeln('Lesson Three = 3');
    : Writeln('Lesson Four = 4');
    : Writeln('Lesson Five = 5');
    : Readln(ChoiceFriday);
    : writeln;
    :
    : Case ChoiceFriday of 1: writeln('Lesson One on Friday is Geology');
    : 2: writeln('Lesson Two on Friday is Geology');
    : 3: writeln('Lesson Three on Friday is Maths');
    : 4: writeln('Lesson Four on Friday is Maths');
    : 5: writeln('Lesson Five on Friday is Physics');
    : Else writeln('There are only 5 Lessons a day, you have made a mistake!');
    : End;
    :
    :
    :
    : End.
    :
    If-then statements only run the first line after the then, until the semi-colon (;). To include more statements in an if-then statement, you should use begin-end. Example: See the difference between these two:
    [code]
    var
    i: integer;
    begin
    readln(i);
    if i = 0 then
    writeln('Is only shown if i = 0');
    writeln('Is always shown');
    end;
    [/code]
    [code]
    var
    i: integer;
    begin
    readln(i);
    if i = 0 then
    begin
    writeln('Is only shown if i = 0');
    writeln('Is also only shown if i = 0');
    end;
    end;
    [/code]
  • : : Could someone please help me out with this code which i have been writing using case
    : :
    : : I am new to programming and therefore this is probably an easy problem to solve, i have been asked to write a school timetable program which displays which lesson is at a user specified time in the week. Could someone please show me where this is wrong because the selections for monday are being used for every day (this should become clearer when the code is read) Thank You very much for any support you could give to me in solving this problem.
    : :
    : : Program CaseDemo;
    : : Uses wincrt;
    : :
    : : Var
    : : choice : integer;
    : : choiceMonday : integer;
    : : choiceTuesday : integer;
    : : choiceWednesday : integer;
    : : choiceThursday : integer;
    : : choiceFriday : integer;
    : :
    : : Begin
    : : Writeln('Welcome to the Timetable Guru');
    : : Writeln('Please enter which day of the week it is today');
    : : writeln;
    : :
    : : Writeln('Monday = 1');
    : : Writeln('Tuesday = 2');
    : : Writeln('Wednesday = 3');
    : : Writeln('Thursday = 4');
    : : Writeln('Friday = 5');
    : : Readln(choice);
    : :
    : : writeln;
    : :
    : : Case choice of
    : : 1: writeln('Monday');
    : : 2: writeln('Tuesday');
    : : 3: writeln('Wednesday');
    : : 4: writeln('Thursday');
    : : 5: writeln('Friday');
    : : Else writeln('what day are you talking about? Not recognised!');
    : : End; {end of case statement}
    : :
    : : writeln;
    : : writeln;
    : :
    : : If choice = 1
    : : then writeln ('Choose a Lesson on Monday');
    : :
    : : Writeln('Lesson One = 1');
    : : Writeln('Lesson Two = 2');
    : : Writeln('Lesson Three = 3');
    : : Writeln('Lesson Four = 4');
    : : Writeln('Lesson Five = 5');
    : : Readln(ChoiceMonday);
    : : writeln;
    : :
    : : Case ChoiceMonday of 1: writeln('Lesson One on Monday is Computing');
    : : 2: writeln('Lesson Two on Monday is Computing');
    : : 3: writeln('Lesson Three on Monday is a free Period');
    : : 4: writeln('Lesson Four on Monday is a free Period');
    : : 5: writeln('Lesson Five on Monday is a free Period');
    : : Else writeln('There are only 5 Lessons a day, you have made a mistake!');
    : : End;
    : : End.
    : :
    : : writeln;
    : : writeln;
    : :
    : : If choice = 2
    : : then writeln ('Choose a lesson on Tuesday');
    : :
    : : Writeln('Lesson One = 1');
    : : Writeln('Lesson Two = 2');
    : : Writeln('Lesson Three = 3');
    : : Writeln('Lesson Four = 4');
    : : Writeln('Lesson Five = 5');
    : : Readln(ChoiceTuesday);
    : : writeln;
    : :
    : : Case ChoiceTuesday of 1: writeln('Lesson One on Tuesday is Physics');
    : : 2: writeln('Lesson Two on Tuesday is Physics');
    : : 3: writeln('Lesson Three on Tuesday is Geology');
    : : 4: writeln('Lesson Four on Tuesday is Geology');
    : : 5: writeln('Lesson Five on Tuesday is Maths');
    : : Else writeln('There are only 5 Lessons a day, you have made a mistake!');
    : : End;
    : : End.
    : :
    : : writeln;
    : : writeln;
    : :
    : : If choice = 3
    : : then writeln ('Choose a lesson on Wednesday');
    : :
    : : Writeln('Lesson One = 1');
    : : Writeln('Lesson Two = 2');
    : : Writeln('Lesson Three = 3');
    : : Writeln('Lesson Four = 4');
    : : Writeln('Lesson Five = 5');
    : : Readln(ChoiceWednesday);
    : : writeln;
    : :
    : : Case ChoiceWednesday of 1: writeln('Lesson One on Wednesday is a free Period');
    : : 2: writeln('Lesson Two on Wednesday is a free Period');
    : : 3: writeln('Lesson Three on Wednesday is Physics');
    : : 4: writeln('Lesson Four on Wednesday is Physics');
    : : 5: writeln('Lesson Five on Wednesday is Computing');
    : : Else writeln('There are only 5 Lessons a day, you have made a mistake!');
    : : End;
    : : End.
    : :
    : : writeln;
    : : writeln;
    : :
    : : If choice = 2
    : : then writeln ('Choose a lesson on Thursday');
    : :
    : : Writeln('Lesson One = 1');
    : : Writeln('Lesson Two = 2');
    : : Writeln('Lesson Three = 3');
    : : Writeln('Lesson Four = 4');
    : : Writeln('Lesson Five = 5');
    : : Readln(ChoiceThursday);
    : : writeln;
    : :
    : : Case ChoiceThursday of 1: writeln('Lesson One on Thursday is Maths');
    : : 2: writeln('Lesson Two on Thursday is Maths');
    : : 3: writeln('Lesson Three on Thursday is Computing');
    : : 4: writeln('Lesson Four on Thursday is Computing');
    : : 5: writeln('Lesson Five on Thursday is a free Period');
    : : Else writeln('There are only 5 Lessons a day, you have made a mistake!');
    : : End;
    : : End.
    : :
    : : writeln;
    : : writeln;
    : :
    : : If choice = 2
    : : then writeln ('Choose a lesson on Friday');
    : : writeln;
    : : Writeln('Lesson One = 1');
    : : Writeln('Lesson Two = 2');
    : : Writeln('Lesson Three = 3');
    : : Writeln('Lesson Four = 4');
    : : Writeln('Lesson Five = 5');
    : : Readln(ChoiceFriday);
    : : writeln;
    : :
    : : Case ChoiceFriday of 1: writeln('Lesson One on Friday is Geology');
    : : 2: writeln('Lesson Two on Friday is Geology');
    : : 3: writeln('Lesson Three on Friday is Maths');
    : : 4: writeln('Lesson Four on Friday is Maths');
    : : 5: writeln('Lesson Five on Friday is Physics');
    : : Else writeln('There are only 5 Lessons a day, you have made a mistake!');
    : : End;
    : :
    : :
    : :
    : : End.
    : :
    : If-then statements only run the first line after the then, until the semi-colon (;). To include more statements in an if-then statement, you should use begin-end. Example: See the difference between these two:
    : [code]
    : var
    : i: integer;
    : begin
    : readln(i);
    : if i = 0 then
    : writeln('Is only shown if i = 0');
    : writeln('Is always shown');
    : end;
    : [/code]
    : [code]
    : var
    : i: integer;
    : begin
    : readln(i);
    : if i = 0 then
    : begin
    : writeln('Is only shown if i = 0');
    : writeln('Is also only shown if i = 0');
    : end;
    : end;
    : [/code]
    :
    thank you for your help, i knew it would be something simple but my lack of knowledge meant that i would be completely stuck with that problem.
    i now have the correct lessons displaying on the correct days
Sign In or Register to comment.