Pascal

Moderators: None (Apply to moderate this forum)
Number of threads: 4106
Number of posts: 14016

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
a "return to prev question" function Posted by dadio on 29 Dec 2006 at 4:19 PM
whats up guys?

i need some help here desperately before new years day 2007.
The program was written in Turbo Pascal 7.0

The program asks the user a series of questions (each on a different screen) where the user either has to input Y or N (for yes or no).
However i am trying to figure out a way for the user to go back to the previous question at anytime and also a seperate function to exit to the main menu at any time...any ideas?

this is for a school project which has to be submitted before new years day.
thanks
Report
Re: a "return to prev question" function Posted by zibadian on 29 Dec 2006 at 4:51 PM
: whats up guys?
:
: i need some help here desperately before new years day 2007.
: The program was written in Turbo Pascal 7.0
:
: The program asks the user a series of questions (each on a different screen) where the user either has to input Y or N (for yes or no).
: However i am trying to figure out a way for the user to go back to the previous question at anytime and also a seperate function to exit to the main menu at any time...any ideas?
:
: this is for a school project which has to be submitted before new years day.
: thanks
:
Depending on the rest of the code, you could keep track of the index of the current question. Then returning to the previous question will be as simple as decreasing the index and showing the current question.
Exiting from the current question, can be accomplished by presenting a 3rd choice to each question. This choice jumps back to the main menu.
Report
Re: a "return to prev question" function Posted by dadio on 29 Dec 2006 at 5:17 PM
: : whats up guys?
: :
: : i need some help here desperately before new years day 2007.
: : The program was written in Turbo Pascal 7.0
: :
: : The program asks the user a series of questions (each on a different screen) where the user either has to input Y or N (for yes or no).
: : However i am trying to figure out a way for the user to go back to the previous question at anytime and also a seperate function to exit to the main menu at any time...any ideas?
: :
: : this is for a school project which has to be submitted before new years day.
: : thanks
: :
: Depending on the rest of the code, you could keep track of the index of the current question. Then returning to the previous question will be as simple as decreasing the index and showing the current question.
: Exiting from the current question, can be accomplished by presenting a 3rd choice to each question. This choice jumps back to the main menu.
:


thanks .....but the program sructure is pretty simple and does not have indexing as such...pls see a sample...of one of the procedures..

what happens is depending on the number of Y or N answers inputed by the user, the prgram would call the next appropriate procedure....the results are not stored in anyway...it is jus done via a counter...take a look:

procedure cataractinference;
begin

clrscr; pageheader('Cataract Testing - Inference');
if count >=4 then
begin
gotoxy(20,10);writeln('suspect cataract');
gotoxy(20,12);writeln('assign patient to cataract specialist');
readln;
end
else
uveitistest; {another procedure}
end;


procedure cataracttest;
begin
count := 0;
screenname := 'Cataract Testing';
askquestion(screenname,'Are you diabetic? Y/N');
askquestion(screenname,'Do colours appear to be faded or dull? Y/N');
askquestion(screenname,'Have you been overexposed to the sun in the past? Y/N');
askquestion(screenname,'Do lights appear to be too bright, or is there a halo around light? Y/N');
askquestion(screenname,'Do you have to change your eye prescription regularly? Y/N');
askquestion(screenname,'Do you have double vision? Y/N');
cataractinference;
end;


so as you can see, it is very difficult in this lay out to be able to go back to a prv question...any suggestions?

Report
Re: a "return to prev question" function Posted by zibadian on 29 Dec 2006 at 5:34 PM
: : : whats up guys?
: : :
: : : i need some help here desperately before new years day 2007.
: : : The program was written in Turbo Pascal 7.0
: : :
: : : The program asks the user a series of questions (each on a different screen) where the user either has to input Y or N (for yes or no).
: : : However i am trying to figure out a way for the user to go back to the previous question at anytime and also a seperate function to exit to the main menu at any time...any ideas?
: : :
: : : this is for a school project which has to be submitted before new years day.
: : : thanks
: : :
: : Depending on the rest of the code, you could keep track of the index of the current question. Then returning to the previous question will be as simple as decreasing the index and showing the current question.
: : Exiting from the current question, can be accomplished by presenting a 3rd choice to each question. This choice jumps back to the main menu.
: :
:
:
: thanks .....but the program sructure is pretty simple and does not have indexing as such...pls see a sample...of one of the procedures..
:
: what happens is depending on the number of Y or N answers inputed by the user, the prgram would call the next appropriate procedure....the results are not stored in anyway...it is jus done via a counter...take a look:
:
: procedure cataractinference;
: begin
:
: clrscr; pageheader('Cataract Testing - Inference');
: if count >=4 then
: begin
: gotoxy(20,10);writeln('suspect cataract');
: gotoxy(20,12);writeln('assign patient to cataract specialist');
: readln;
: end
: else
: uveitistest; {another procedure}
: end;
:
:
: procedure cataracttest;
: begin
: count := 0;
: screenname := 'Cataract Testing';
: askquestion(screenname,'Are you diabetic? Y/N');
: askquestion(screenname,'Do colours appear to be faded or dull? Y/N');
: askquestion(screenname,'Have you been overexposed to the sun in the past? Y/N');
: askquestion(screenname,'Do lights appear to be too bright, or is there a halo around light? Y/N');
: askquestion(screenname,'Do you have to change your eye prescription regularly? Y/N');
: askquestion(screenname,'Do you have double vision? Y/N');
: cataractinference;
: end;
:
:
: so as you can see, it is very difficult in this lay out to be able to go back to a prv question...any suggestions?
:
:
Use a repeat-until loop around the askquestion() calls. Then using a case-of statement you can create the index method easily. This is not a very neat way to do, but it works. Example:
  index := 0;
  screenname := 'Cataract Testing';
  repeat
    case index of
      0: askquestion(screenname,'Are you diabetic? Y/N');
      1: askquestion(screenname,'Do colours appear to be faded or dull? Y/N');
      2: askquestion(screenname,'Have you been overexposed to the sun in the past? Y/N');
      { Etc. }
      5: askquestion(screenname,'Do you have double vision? Y/N');
      else Exit; { Jump back to main menu }
    end;
  until index = 6 {number of questions };
  cataractinference;


Report
Re: a "return to prev question" function Posted by dadio on 29 Dec 2006 at 6:13 PM
: : : : whats up guys?
: : : :
: : : : i need some help here desperately before new years day 2007.
: : : : The program was written in Turbo Pascal 7.0
: : : :
: : : : The program asks the user a series of questions (each on a different screen) where the user either has to input Y or N (for yes or no).
: : : : However i am trying to figure out a way for the user to go back to the previous question at anytime and also a seperate function to exit to the main menu at any time...any ideas?
: : : :
: : : : this is for a school project which has to be submitted before new years day.
: : : : thanks
: : : :
: : : Depending on the rest of the code, you could keep track of the index of the current question. Then returning to the previous question will be as simple as decreasing the index and showing the current question.
: : : Exiting from the current question, can be accomplished by presenting a 3rd choice to each question. This choice jumps back to the main menu.
: : :
: :
: :
: : thanks .....but the program sructure is pretty simple and does not have indexing as such...pls see a sample...of one of the procedures..
: :
: : what happens is depending on the number of Y or N answers inputed by the user, the prgram would call the next appropriate procedure....the results are not stored in anyway...it is jus done via a counter...take a look:
: :
: : procedure cataractinference;
: : begin
: :
: : clrscr; pageheader('Cataract Testing - Inference');
: : if count >=4 then
: : begin
: : gotoxy(20,10);writeln('suspect cataract');
: : gotoxy(20,12);writeln('assign patient to cataract specialist');
: : readln;
: : end
: : else
: : uveitistest; {another procedure}
: : end;
: :
: :
: : procedure cataracttest;
: : begin
: : count := 0;
: : screenname := 'Cataract Testing';
: : askquestion(screenname,'Are you diabetic? Y/N');
: : askquestion(screenname,'Do colours appear to be faded or dull? Y/N');
: : askquestion(screenname,'Have you been overexposed to the sun in the past? Y/N');
: : askquestion(screenname,'Do lights appear to be too bright, or is there a halo around light? Y/N');
: : askquestion(screenname,'Do you have to change your eye prescription regularly? Y/N');
: : askquestion(screenname,'Do you have double vision? Y/N');
: : cataractinference;
: : end;
: :
: :
: : so as you can see, it is very difficult in this lay out to be able to go back to a prv question...any suggestions?
: :
: :
: Use a repeat-until loop around the askquestion() calls. Then using a case-of statement you can create the index method easily. This is not a very neat way to do, but it works. Example:
:
:   index := 0;
:   screenname := 'Cataract Testing';
:   repeat
:     case index of
:       0: askquestion(screenname,'Are you diabetic? Y/N');
:       1: askquestion(screenname,'Do colours appear to be faded or dull? Y/N');
:       2: askquestion(screenname,'Have you been overexposed to the sun in the past? Y/N');
:       { Etc. }
:       5: askquestion(screenname,'Do you have double vision? Y/N');
:       else Exit; { Jump back to main menu }
:     end;
:   until index = 6 {number of questions };
:   cataractinference;
: 

:
:



Thanks again for your help.
however, I am getting unknown identifier at the beginign at index, whichi suppose means the word index needs to be declared some where before....

what do i do.

2.) i see you removed the count function....i think i would need this function, becase remember, if you looked at my code, if a certain number of Y are met, it calls a procedure, else another output happens.


Report
Re: a "return to prev question" function Posted by Phat Nat on 29 Dec 2006 at 10:11 PM
: : : : : whats up guys?
: : : : :
: : : : : i need some help here desperately before new years day 2007.
: : : : : The program was written in Turbo Pascal 7.0
: : : : :
: : : : : The program asks the user a series of questions (each on a different screen) where the user either has to input Y or N (for yes or no).
: : : : : However i am trying to figure out a way for the user to go back to the previous question at anytime and also a seperate function to exit to the main menu at any time...any ideas?
: : : : :
: : : : : this is for a school project which has to be submitted before new years day.
: : : : : thanks
: : : : :
: : : : Depending on the rest of the code, you could keep track of the index of the current question. Then returning to the previous question will be as simple as decreasing the index and showing the current question.
: : : : Exiting from the current question, can be accomplished by presenting a 3rd choice to each question. This choice jumps back to the main menu.
: : : :
: : :
: : :
: : : thanks .....but the program sructure is pretty simple and does not have indexing as such...pls see a sample...of one of the procedures..
: : :
: : : what happens is depending on the number of Y or N answers inputed by the user, the prgram would call the next appropriate procedure....the results are not stored in anyway...it is jus done via a counter...take a look:
: : :
: : : procedure cataractinference;
: : : begin
: : :
: : : clrscr; pageheader('Cataract Testing - Inference');
: : : if count >=4 then
: : : begin
: : : gotoxy(20,10);writeln('suspect cataract');
: : : gotoxy(20,12);writeln('assign patient to cataract specialist');
: : : readln;
: : : end
: : : else
: : : uveitistest; {another procedure}
: : : end;
: : :
: : :
: : : procedure cataracttest;
: : : begin
: : : count := 0;
: : : screenname := 'Cataract Testing';
: : : askquestion(screenname,'Are you diabetic? Y/N');
: : : askquestion(screenname,'Do colours appear to be faded or dull? Y/N');
: : : askquestion(screenname,'Have you been overexposed to the sun in the past? Y/N');
: : : askquestion(screenname,'Do lights appear to be too bright, or is there a halo around light? Y/N');
: : : askquestion(screenname,'Do you have to change your eye prescription regularly? Y/N');
: : : askquestion(screenname,'Do you have double vision? Y/N');
: : : cataractinference;
: : : end;
: : :
: : :
: : : so as you can see, it is very difficult in this lay out to be able to go back to a prv question...any suggestions?
: : :
: : :
: : Use a repeat-until loop around the askquestion() calls. Then using a case-of statement you can create the index method easily. This is not a very neat way to do, but it works. Example:
: :
: :   index := 0;
: :   screenname := 'Cataract Testing';
: :   repeat
: :     case index of
: :       0: askquestion(screenname,'Are you diabetic? Y/N');
: :       1: askquestion(screenname,'Do colours appear to be faded or dull? Y/N');
: :       2: askquestion(screenname,'Have you been overexposed to the sun in the past? Y/N');
: :       { Etc. }
: :       5: askquestion(screenname,'Do you have double vision? Y/N');
: :       else Exit; { Jump back to main menu }
: :     end;
: :   until index = 6 {number of questions };
: :   cataractinference;
: : 

: :
: :
:
:
:
: Thanks again for your help.
: however, I am getting unknown identifier at the beginign at index, whichi suppose means the word index needs to be declared some where before....
:
: what do i do.
:
: 2.) i see you removed the count function....i think i would need this function, becase remember, if you looked at my code, if a certain number of Y are met, it calls a procedure, else another output happens.
:
Yeah, he just swapped names. Change the Index to Count and it should work.

The other way you could do it is like so:
CONST
     CataractCount = 5;
     CataractQuestions : Array[0..CataractCount] Of String = 
     ('Are you diabetic?',
      'Do colours appear to be faded or dull?',
      'Have you been overexposed to the sun in the past?',
      'Do lights appear to be too bright, or is there a halo around light?',
      'Do you have to change your eye prescription regularly?',
      'Do you have double vision?');

{...}

Begin
     Count := 0;
     screenname := 'Cataract Testing';
     repeat
           askquestion(screenname,CataractQuestions[Count]+' Y/N');    
           inc(Count)
     until index = 6 {number of questions };
     cataractinference;
End.


You may want to look at changing your AskQuestion Procedure to a Function and have it return the Answer:
     repeat
           Case askquestion(screenname,CataractQuestions[Count]+' Y/N') Of
            0,1 : inc(Count);   { 0 = No, 1 = Yes }
            2   : Dec(Count);   { 2 = Back a Question }
            3   : Break;        { 3 = Quit Section }
           End;
     until index = 6 {number of questions };


Phat Nat

Report
Re: a "return to prev question" function Posted by zibadian on 30 Dec 2006 at 12:12 PM
: : : : : : whats up guys?
: : : : : :
: : : : : : i need some help here desperately before new years day 2007.
: : : : : : The program was written in Turbo Pascal 7.0
: : : : : :
: : : : : : The program asks the user a series of questions (each on a different screen) where the user either has to input Y or N (for yes or no).
: : : : : : However i am trying to figure out a way for the user to go back to the previous question at anytime and also a seperate function to exit to the main menu at any time...any ideas?
: : : : : :
: : : : : : this is for a school project which has to be submitted before new years day.
: : : : : : thanks
: : : : : :
: : : : : Depending on the rest of the code, you could keep track of the index of the current question. Then returning to the previous question will be as simple as decreasing the index and showing the current question.
: : : : : Exiting from the current question, can be accomplished by presenting a 3rd choice to each question. This choice jumps back to the main menu.
: : : : :
: : : :
: : : :
: : : : thanks .....but the program sructure is pretty simple and does not have indexing as such...pls see a sample...of one of the procedures..
: : : :
: : : : what happens is depending on the number of Y or N answers inputed by the user, the prgram would call the next appropriate procedure....the results are not stored in anyway...it is jus done via a counter...take a look:
: : : :
: : : : procedure cataractinference;
: : : : begin
: : : :
: : : : clrscr; pageheader('Cataract Testing - Inference');
: : : : if count >=4 then
: : : : begin
: : : : gotoxy(20,10);writeln('suspect cataract');
: : : : gotoxy(20,12);writeln('assign patient to cataract specialist');
: : : : readln;
: : : : end
: : : : else
: : : : uveitistest; {another procedure}
: : : : end;
: : : :
: : : :
: : : : procedure cataracttest;
: : : : begin
: : : : count := 0;
: : : : screenname := 'Cataract Testing';
: : : : askquestion(screenname,'Are you diabetic? Y/N');
: : : : askquestion(screenname,'Do colours appear to be faded or dull? Y/N');
: : : : askquestion(screenname,'Have you been overexposed to the sun in the past? Y/N');
: : : : askquestion(screenname,'Do lights appear to be too bright, or is there a halo around light? Y/N');
: : : : askquestion(screenname,'Do you have to change your eye prescription regularly? Y/N');
: : : : askquestion(screenname,'Do you have double vision? Y/N');
: : : : cataractinference;
: : : : end;
: : : :
: : : :
: : : : so as you can see, it is very difficult in this lay out to be able to go back to a prv question...any suggestions?
: : : :
: : : :
: : : Use a repeat-until loop around the askquestion() calls. Then using a case-of statement you can create the index method easily. This is not a very neat way to do, but it works. Example:
: : :
: : :   index := 0;
: : :   screenname := 'Cataract Testing';
: : :   repeat
: : :     case index of
: : :       0: askquestion(screenname,'Are you diabetic? Y/N');
: : :       1: askquestion(screenname,'Do colours appear to be faded or dull? Y/N');
: : :       2: askquestion(screenname,'Have you been overexposed to the sun in the past? Y/N');
: : :       { Etc. }
: : :       5: askquestion(screenname,'Do you have double vision? Y/N');
: : :       else Exit; { Jump back to main menu }
: : :     end;
: : :   until index = 6 {number of questions };
: : :   cataractinference;
: : : 

: : :
: : :
: :
: :
: :
: : Thanks again for your help.
: : however, I am getting unknown identifier at the beginign at index, whichi suppose means the word index needs to be declared some where before....
: :
: : what do i do.
: :
: : 2.) i see you removed the count function....i think i would need this function, becase remember, if you looked at my code, if a certain number of Y are met, it calls a procedure, else another output happens.
: :
: Yeah, he just swapped names. Change the Index to Count and it should work.
:
: The other way you could do it is like so:
:
: CONST
:      CataractCount = 5;
:      CataractQuestions : Array[0..CataractCount] Of String = 
:      ('Are you diabetic?',
:       'Do colours appear to be faded or dull?',
:       'Have you been overexposed to the sun in the past?',
:       'Do lights appear to be too bright, or is there a halo around light?',
:       'Do you have to change your eye prescription regularly?',
:       'Do you have double vision?');
: 
: {...}
: 
: Begin
:      Count := 0;
:      screenname := 'Cataract Testing';
:      repeat
:            askquestion(screenname,CataractQuestions[Count]+' Y/N');    
:            inc(Count)
:      until index = 6 {number of questions };
:      cataractinference;
: End.
: 

:
: You may want to look at changing your AskQuestion Procedure to a Function and have it return the Answer:
:
:      repeat
:            Case askquestion(screenname,CataractQuestions[Count]+' Y/N') Of
:             0,1 : inc(Count);   { 0 = No, 1 = Yes }
:             2   : Dec(Count);   { 2 = Back a Question }
:             3   : Break;        { 3 = Quit Section }
:            End;
:      until index = 6 {number of questions };
: 

:
: Phat Nat
:
:
I didn't swap Count and Index, because Count determines if someone is suspected of cataract. I forgot Count, since it wasn't an important part of my example. Just add count to the example as shown with screenname.
Report
Re: a "return to prev question" function Posted by dadio on 30 Dec 2006 at 3:43 PM
: : : : : : : whats up guys?
: : : : : : :
: : : : : : : i need some help here desperately before new years day 2007.
: : : : : : : The program was written in Turbo Pascal 7.0
: : : : : : :
: : : : : : : The program asks the user a series of questions (each on a different screen) where the user either has to input Y or N (for yes or no).
: : : : : : : However i am trying to figure out a way for the user to go back to the previous question at anytime and also a seperate function to exit to the main menu at any time...any ideas?
: : : : : : :
: : : : : : : this is for a school project which has to be submitted before new years day.
: : : : : : : thanks
: : : : : : :
: : : : : : Depending on the rest of the code, you could keep track of the index of the current question. Then returning to the previous question will be as simple as decreasing the index and showing the current question.
: : : : : : Exiting from the current question, can be accomplished by presenting a 3rd choice to each question. This choice jumps back to the main menu.
: : : : : :
: : : : :
: : : : :
: : : : : thanks .....but the program sructure is pretty simple and does not have indexing as such...pls see a sample...of one of the procedures..
: : : : :
: : : : : what happens is depending on the number of Y or N answers inputed by the user, the prgram would call the next appropriate procedure....the results are not stored in anyway...it is jus done via a counter...take a look:
: : : : :
: : : : : procedure cataractinference;
: : : : : begin
: : : : :
: : : : : clrscr; pageheader('Cataract Testing - Inference');
: : : : : if count >=4 then
: : : : : begin
: : : : : gotoxy(20,10);writeln('suspect cataract');
: : : : : gotoxy(20,12);writeln('assign patient to cataract specialist');
: : : : : readln;
: : : : : end
: : : : : else
: : : : : uveitistest; {another procedure}
: : : : : end;
: : : : :
: : : : :
: : : : : procedure cataracttest;
: : : : : begin
: : : : : count := 0;
: : : : : screenname := 'Cataract Testing';
: : : : : askquestion(screenname,'Are you diabetic? Y/N');
: : : : : askquestion(screenname,'Do colours appear to be faded or dull? Y/N');
: : : : : askquestion(screenname,'Have you been overexposed to the sun in the past? Y/N');
: : : : : askquestion(screenname,'Do lights appear to be too bright, or is there a halo around light? Y/N');
: : : : : askquestion(screenname,'Do you have to change your eye prescription regularly? Y/N');
: : : : : askquestion(screenname,'Do you have double vision? Y/N');
: : : : : cataractinference;
: : : : : end;
: : : : :
: : : : :
: : : : : so as you can see, it is very difficult in this lay out to be able to go back to a prv question...any suggestions?
: : : : :
: : : : :
: : : : Use a repeat-until loop around the askquestion() calls. Then using a case-of statement you can create the index method easily. This is not a very neat way to do, but it works. Example:
: : : :
: : : :   index := 0;
: : : :   screenname := 'Cataract Testing';
: : : :   repeat
: : : :     case index of
: : : :       0: askquestion(screenname,'Are you diabetic? Y/N');
: : : :       1: askquestion(screenname,'Do colours appear to be faded or dull? Y/N');
: : : :       2: askquestion(screenname,'Have you been overexposed to the sun in the past? Y/N');
: : : :       { Etc. }
: : : :       5: askquestion(screenname,'Do you have double vision? Y/N');
: : : :       else Exit; { Jump back to main menu }
: : : :     end;
: : : :   until index = 6 {number of questions };
: : : :   cataractinference;
: : : : 

: : : :
: : : :
: : :
: : :
: : :
: : : Thanks again for your help.
: : : however, I am getting unknown identifier at the beginign at index, whichi suppose means the word index needs to be declared some where before....
: : :
: : : what do i do.
: : :
: : : 2.) i see you removed the count function....i think i would need this function, becase remember, if you looked at my code, if a certain number of Y are met, it calls a procedure, else another output happens.
: : :
: : Yeah, he just swapped names. Change the Index to Count and it should work.
: :
: : The other way you could do it is like so:
: :
: : CONST
: :      CataractCount = 5;
: :      CataractQuestions : Array[0..CataractCount] Of String = 
: :      ('Are you diabetic?',
: :       'Do colours appear to be faded or dull?',
: :       'Have you been overexposed to the sun in the past?',
: :       'Do lights appear to be too bright, or is there a halo around light?',
: :       'Do you have to change your eye prescription regularly?',
: :       'Do you have double vision?');
: : 
: : {...}
: : 
: : Begin
: :      Count := 0;
: :      screenname := 'Cataract Testing';
: :      repeat
: :            askquestion(screenname,CataractQuestions[Count]+' Y/N');    
: :            inc(Count)
: :      until index = 6 {number of questions };
: :      cataractinference;
: : End.
: : 

: :
: : You may want to look at changing your AskQuestion Procedure to a Function and have it return the Answer:
: :
: :      repeat
: :            Case askquestion(screenname,CataractQuestions[Count]+' Y/N') Of
: :             0,1 : inc(Count);   { 0 = No, 1 = Yes }
: :             2   : Dec(Count);   { 2 = Back a Question }
: :             3   : Break;        { 3 = Quit Section }
: :            End;
: :      until index = 6 {number of questions };
: : 

: :
: : Phat Nat
: :
: :
: I didn't swap Count and Index, because Count determines if someone is suspected of cataract. I forgot Count, since it wasn't an important part of my example. Just add count to the example as shown with screenname.
:
........uhhh...i'm lost
Report
Re: a "return to prev question" function Posted by zibadian on 30 Dec 2006 at 3:53 PM
: : : : : : : : whats up guys?
: : : : : : : :
: : : : : : : : i need some help here desperately before new years day 2007.
: : : : : : : : The program was written in Turbo Pascal 7.0
: : : : : : : :
: : : : : : : : The program asks the user a series of questions (each on a different screen) where the user either has to input Y or N (for yes or no).
: : : : : : : : However i am trying to figure out a way for the user to go back to the previous question at anytime and also a seperate function to exit to the main menu at any time...any ideas?
: : : : : : : :
: : : : : : : : this is for a school project which has to be submitted before new years day.
: : : : : : : : thanks
: : : : : : : :
: : : : : : : Depending on the rest of the code, you could keep track of the index of the current question. Then returning to the previous question will be as simple as decreasing the index and showing the current question.
: : : : : : : Exiting from the current question, can be accomplished by presenting a 3rd choice to each question. This choice jumps back to the main menu.
: : : : : : :
: : : : : :
: : : : : :
: : : : : : thanks .....but the program sructure is pretty simple and does not have indexing as such...pls see a sample...of one of the procedures..
: : : : : :
: : : : : : what happens is depending on the number of Y or N answers inputed by the user, the prgram would call the next appropriate procedure....the results are not stored in anyway...it is jus done via a counter...take a look:
: : : : : :
: : : : : : procedure cataractinference;
: : : : : : begin
: : : : : :
: : : : : : clrscr; pageheader('Cataract Testing - Inference');
: : : : : : if count >=4 then
: : : : : : begin
: : : : : : gotoxy(20,10);writeln('suspect cataract');
: : : : : : gotoxy(20,12);writeln('assign patient to cataract specialist');
: : : : : : readln;
: : : : : : end
: : : : : : else
: : : : : : uveitistest; {another procedure}
: : : : : : end;
: : : : : :
: : : : : :
: : : : : : procedure cataracttest;
: : : : : : begin
: : : : : : count := 0;
: : : : : : screenname := 'Cataract Testing';
: : : : : : askquestion(screenname,'Are you diabetic? Y/N');
: : : : : : askquestion(screenname,'Do colours appear to be faded or dull? Y/N');
: : : : : : askquestion(screenname,'Have you been overexposed to the sun in the past? Y/N');
: : : : : : askquestion(screenname,'Do lights appear to be too bright, or is there a halo around light? Y/N');
: : : : : : askquestion(screenname,'Do you have to change your eye prescription regularly? Y/N');
: : : : : : askquestion(screenname,'Do you have double vision? Y/N');
: : : : : : cataractinference;
: : : : : : end;
: : : : : :
: : : : : :
: : : : : : so as you can see, it is very difficult in this lay out to be able to go back to a prv question...any suggestions?
: : : : : :
: : : : : :
: : : : : Use a repeat-until loop around the askquestion() calls. Then using a case-of statement you can create the index method easily. This is not a very neat way to do, but it works. Example:
: : : : :
: : : : :   index := 0;
: : : : :   screenname := 'Cataract Testing';
: : : : :   repeat
: : : : :     case index of
: : : : :       0: askquestion(screenname,'Are you diabetic? Y/N');
: : : : :       1: askquestion(screenname,'Do colours appear to be faded or dull? Y/N');
: : : : :       2: askquestion(screenname,'Have you been overexposed to the sun in the past? Y/N');
: : : : :       { Etc. }
: : : : :       5: askquestion(screenname,'Do you have double vision? Y/N');
: : : : :       else Exit; { Jump back to main menu }
: : : : :     end;
: : : : :   until index = 6 {number of questions };
: : : : :   cataractinference;
: : : : : 

: : : : :
: : : : :
: : : :
: : : :
: : : :
: : : : Thanks again for your help.
: : : : however, I am getting unknown identifier at the beginign at index, whichi suppose means the word index needs to be declared some where before....
: : : :
: : : : what do i do.
: : : :
: : : : 2.) i see you removed the count function....i think i would need this function, becase remember, if you looked at my code, if a certain number of Y are met, it calls a procedure, else another output happens.
: : : :
: : : Yeah, he just swapped names. Change the Index to Count and it should work.
: : :
: : : The other way you could do it is like so:
: : :
: : : CONST
: : :      CataractCount = 5;
: : :      CataractQuestions : Array[0..CataractCount] Of String = 
: : :      ('Are you diabetic?',
: : :       'Do colours appear to be faded or dull?',
: : :       'Have you been overexposed to the sun in the past?',
: : :       'Do lights appear to be too bright, or is there a halo around light?',
: : :       'Do you have to change your eye prescription regularly?',
: : :       'Do you have double vision?');
: : : 
: : : {...}
: : : 
: : : Begin
: : :      Count := 0;
: : :      screenname := 'Cataract Testing';
: : :      repeat
: : :            askquestion(screenname,CataractQuestions[Count]+' Y/N');    
: : :            inc(Count)
: : :      until index = 6 {number of questions };
: : :      cataractinference;
: : : End.
: : : 

: : :
: : : You may want to look at changing your AskQuestion Procedure to a Function and have it return the Answer:
: : :
: : :      repeat
: : :            Case askquestion(screenname,CataractQuestions[Count]+' Y/N') Of
: : :             0,1 : inc(Count);   { 0 = No, 1 = Yes }
: : :             2   : Dec(Count);   { 2 = Back a Question }
: : :             3   : Break;        { 3 = Quit Section }
: : :            End;
: : :      until index = 6 {number of questions };
: : : 

: : :
: : : Phat Nat
: : :
: : :
: : I didn't swap Count and Index, because Count determines if someone is suspected of cataract. I forgot Count, since it wasn't an important part of my example. Just add count to the example as shown with screenname.
: :
: ........uhhh...i'm lost
:
Index holds the index of the current question, which is shown to the user. Count is still the same as in your original program. Based on your original code it is the number of times the user answered yes. The only addition to your program I made, was an repeat-until loop, case-of statement and the Index variable to control which question is shown. All other code is exactly the same.
Report
Re: a "return to prev question" function Posted by dadio on 30 Dec 2006 at 5:37 PM
: : : : : whats up guys?
: : : : :
: : : : : i need some help here desperately before new years day 2007.
: : : : : The program was written in Turbo Pascal 7.0
: : : : :
: : : : : The program asks the user a series of questions (each on a different screen) where the user either has to input Y or N (for yes or no).
: : : : : However i am trying to figure out a way for the user to go back to the previous question at anytime and also a seperate function to exit to the main menu at any time...any ideas?
: : : : :
: : : : : this is for a school project which has to be submitted before new years day.
: : : : : thanks
: : : : :
: : : : Depending on the rest of the code, you could keep track of the index of the current question. Then returning to the previous question will be as simple as decreasing the index and showing the current question.
: : : : Exiting from the current question, can be accomplished by presenting a 3rd choice to each question. This choice jumps back to the main menu.
: : : :
: : :
: : :
: : : thanks .....but the program sructure is pretty simple and does not have indexing as such...pls see a sample...of one of the procedures..
: : :
: : : what happens is depending on the number of Y or N answers inputed by the user, the prgram would call the next appropriate procedure....the results are not stored in anyway...it is jus done via a counter...take a look:
: : :
: : : procedure cataractinference;
: : : begin
: : :
: : : clrscr; pageheader('Cataract Testing - Inference');
: : : if count >=4 then
: : : begin
: : : gotoxy(20,10);writeln('suspect cataract');
: : : gotoxy(20,12);writeln('assign patient to cataract specialist');
: : : readln;
: : : end
: : : else
: : : uveitistest; {another procedure}
: : : end;
: : :
: : :
: : : procedure cataracttest;
: : : begin
: : : count := 0;
: : : screenname := 'Cataract Testing';
: : : askquestion(screenname,'Are you diabetic? Y/N');
: : : askquestion(screenname,'Do colours appear to be faded or dull? Y/N');
: : : askquestion(screenname,'Have you been overexposed to the sun in the past? Y/N');
: : : askquestion(screenname,'Do lights appear to be too bright, or is there a halo around light? Y/N');
: : : askquestion(screenname,'Do you have to change your eye prescription regularly? Y/N');
: : : askquestion(screenname,'Do you have double vision? Y/N');
: : : cataractinference;
: : : end;
: : :
: : :
: : : so as you can see, it is very difficult in this lay out to be able to go back to a prv question...any suggestions?
: : :
: : :
: : Use a repeat-until loop around the askquestion() calls. Then using a case-of statement you can create the index method easily. This is not a very neat way to do, but it works. Example:
: :
: :   index := 0;
: :   screenname := 'Cataract Testing';
: :   repeat
: :     case index of
: :       0: askquestion(screenname,'Are you diabetic? Y/N');
: :       1: askquestion(screenname,'Do colours appear to be faded or dull? Y/N');
: :       2: askquestion(screenname,'Have you been overexposed to the sun in the past? Y/N');
: :       { Etc. }
: :       5: askquestion(screenname,'Do you have double vision? Y/N');
: :       else Exit; { Jump back to main menu }
: :     end;
: :   until index = 6 {number of questions };
: :   cataractinference;
: : 

: :
: :
:
:
:
: Thanks again for your help.
: however, I am getting unknown identifier at the beginign at index, whichi suppose means the word index needs to be declared some where before....
:
: what do i do.
:
: 2.) i see you removed the count function....i think i would need this function, becase remember, if you looked at my code, if a certain number of Y are met, it calls a procedure, else another output happens.
:
:
:

ok i got it....i implemented the code, so it now looks like:

procedure cataractinference;
begin

    clrscr; pageheader('Cataract Testing - Inference');
    if count >=4 then
    begin
         gotoxy(20,10);writeln('suspect cataract');
         gotoxy(20,12);writeln('assign patient to cataract specialist');
         readln;
    end
    else
        uveitistest;
end;


procedure cataracttest;
begin
     count := 0;
     index:=0;
     repeat
     screenname := 'Cataract Testing';
     case index of    
     0: askquestion(screenname,'Are you diabetic? Y/N');
     1: askquestion(screenname,'Do colours appear to be faded or dull? Y/N');
     2: askquestion(screenname,'Have you been overexposed to the sun in the past? Y/N');
     3: askquestion(screenname,'Do lights appear to be too bright, or is there a halo around light? Y/N');
     4: askquestion(screenname,'Do you have to change your eye prescription regularly? Y/N');
     5: askquestion(screenname,'Do you have double vision? Y/N');
     else Exit;
end;
until index=6;     
cataractinference;

readln;
end;



the program runs now...but when it comes to the first question which is
"are you diabetic Y/N"? and i enter any value..whether it be Y /or N or anything, the program just stays there and i have to use the ctrl break function to exit...but it used to work before.... *confused*
Report
Re: a "return to prev question" function Posted by zibadian on 30 Dec 2006 at 7:24 PM
: : : : : : whats up guys?
: : : : : :
: : : : : : i need some help here desperately before new years day 2007.
: : : : : : The program was written in Turbo Pascal 7.0
: : : : : :
: : : : : : The program asks the user a series of questions (each on a different screen) where the user either has to input Y or N (for yes or no).
: : : : : : However i am trying to figure out a way for the user to go back to the previous question at anytime and also a seperate function to exit to the main menu at any time...any ideas?
: : : : : :
: : : : : : this is for a school project which has to be submitted before new years day.
: : : : : : thanks
: : : : : :
: : : : : Depending on the rest of the code, you could keep track of the index of the current question. Then returning to the previous question will be as simple as decreasing the index and showing the current question.
: : : : : Exiting from the current question, can be accomplished by presenting a 3rd choice to each question. This choice jumps back to the main menu.
: : : : :
: : : :
: : : :
: : : : thanks .....but the program sructure is pretty simple and does not have indexing as such...pls see a sample...of one of the procedures..
: : : :
: : : : what happens is depending on the number of Y or N answers inputed by the user, the prgram would call the next appropriate procedure....the results are not stored in anyway...it is jus done via a counter...take a look:
: : : :
: : : : procedure cataractinference;
: : : : begin
: : : :
: : : : clrscr; pageheader('Cataract Testing - Inference');
: : : : if count >=4 then
: : : : begin
: : : : gotoxy(20,10);writeln('suspect cataract');
: : : : gotoxy(20,12);writeln('assign patient to cataract specialist');
: : : : readln;
: : : : end
: : : : else
: : : : uveitistest; {another procedure}
: : : : end;
: : : :
: : : :
: : : : procedure cataracttest;
: : : : begin
: : : : count := 0;
: : : : screenname := 'Cataract Testing';
: : : : askquestion(screenname,'Are you diabetic? Y/N');
: : : : askquestion(screenname,'Do colours appear to be faded or dull? Y/N');
: : : : askquestion(screenname,'Have you been overexposed to the sun in the past? Y/N');
: : : : askquestion(screenname,'Do lights appear to be too bright, or is there a halo around light? Y/N');
: : : : askquestion(screenname,'Do you have to change your eye prescription regularly? Y/N');
: : : : askquestion(screenname,'Do you have double vision? Y/N');
: : : : cataractinference;
: : : : end;
: : : :
: : : :
: : : : so as you can see, it is very difficult in this lay out to be able to go back to a prv question...any suggestions?
: : : :
: : : :
: : : Use a repeat-until loop around the askquestion() calls. Then using a case-of statement you can create the index method easily. This is not a very neat way to do, but it works. Example:
: : :
: : :   index := 0;
: : :   screenname := 'Cataract Testing';
: : :   repeat
: : :     case index of
: : :       0: askquestion(screenname,'Are you diabetic? Y/N');
: : :       1: askquestion(screenname,'Do colours appear to be faded or dull? Y/N');
: : :       2: askquestion(screenname,'Have you been overexposed to the sun in the past? Y/N');
: : :       { Etc. }
: : :       5: askquestion(screenname,'Do you have double vision? Y/N');
: : :       else Exit; { Jump back to main menu }
: : :     end;
: : :   until index = 6 {number of questions };
: : :   cataractinference;
: : : 

: : :
: : :
: :
: :
: :
: : Thanks again for your help.
: : however, I am getting unknown identifier at the beginign at index, whichi suppose means the word index needs to be declared some where before....
: :
: : what do i do.
: :
: : 2.) i see you removed the count function....i think i would need this function, becase remember, if you looked at my code, if a certain number of Y are met, it calls a procedure, else another output happens.
: :
: :
: :
:
: ok i got it....i implemented the code, so it now looks like:
:
:
: procedure cataractinference;
: begin
: 
:     clrscr; pageheader('Cataract Testing - Inference');
:     if count >=4 then
:     begin
:          gotoxy(20,10);writeln('suspect cataract');
:          gotoxy(20,12);writeln('assign patient to cataract specialist');
:          readln;
:     end
:     else
:         uveitistest;
: end;
: 
: 
: procedure cataracttest;
: begin
:      count := 0;
:      index:=0;
:      repeat
:      screenname := 'Cataract Testing';
:      case index of    
:      0: askquestion(screenname,'Are you diabetic? Y/N');
:      1: askquestion(screenname,'Do colours appear to be faded or dull? Y/N');
:      2: askquestion(screenname,'Have you been overexposed to the sun in the past? Y/N');
:      3: askquestion(screenname,'Do lights appear to be too bright, or is there a halo around light? Y/N');
:      4: askquestion(screenname,'Do you have to change your eye prescription regularly? Y/N');
:      5: askquestion(screenname,'Do you have double vision? Y/N');
:      else Exit;
: end;
: until index=6;     
: cataractinference;
: 
: readln;
: end;
: 
: 

:
: the program runs now...but when it comes to the first question which is
: "are you diabetic Y/N"? and i enter any value..whether it be Y /or N or anything, the program just stays there and i have to use the ctrl break function to exit...but it used to work before.... *confused*
:
After each question, you should increase the index by 1 to go to the next question. Remember that the value stored in the Index variable determines which question the user gets to see, not the order in which the questions are coded.
Report
Re: a "return to prev question" function Posted by dadio on 31 Dec 2006 at 8:53 AM
: : : : : : : whats up guys?
: : : : : : :
: : : : : : : i need some help here desperately before new years day 2007.
: : : : : : : The program was written in Turbo Pascal 7.0
: : : : : : :
: : : : : : : The program asks the user a series of questions (each on a different screen) where the user either has to input Y or N (for yes or no).
: : : : : : : However i am trying to figure out a way for the user to go back to the previous question at anytime and also a seperate function to exit to the main menu at any time...any ideas?
: : : : : : :
: : : : : : : this is for a school project which has to be submitted before new years day.
: : : : : : : thanks




trying...but only getting errors......pls help...can u do the code....? thanks...
: : : : : : :
: : : : : : Depending on the rest of the code, you could keep track of the index of the current question. Then returning to the previous question will be as simple as decreasing the index and showing the current question.
: : : : : : Exiting from the current question, can be accomplished by presenting a 3rd choice to each question. This choice jumps back to the main menu.
: : : : : :
: : : : :
: : : : :
: : : : : thanks .....but the program sructure is pretty simple and does not have indexing as such...pls see a sample...of one of the procedures..
: : : : :
: : : : : what happens is depending on the number of Y or N answers inputed by the user, the prgram would call the next appropriate procedure....the results are not stored in anyway...it is jus done via a counter...take a look:
: : : : :
: : : : : procedure cataractinference;
: : : : : begin
: : : : :
: : : : : clrscr; pageheader('Cataract Testing - Inference');
: : : : : if count >=4 then
: : : : : begin
: : : : : gotoxy(20,10);writeln('suspect cataract');
: : : : : gotoxy(20,12);writeln('assign patient to cataract specialist');
: : : : : readln;
: : : : : end
: : : : : else
: : : : : uveitistest; {another procedure}
: : : : : end;
: : : : :
: : : : :
: : : : : procedure cataracttest;
: : : : : begin
: : : : : count := 0;
: : : : : screenname := 'Cataract Testing';
: : : : : askquestion(screenname,'Are you diabetic? Y/N');
: : : : : askquestion(screenname,'Do colours appear to be faded or dull? Y/N');
: : : : : askquestion(screenname,'Have you been overexposed to the sun in the past? Y/N');
: : : : : askquestion(screenname,'Do lights appear to be too bright, or is there a halo around light? Y/N');
: : : : : askquestion(screenname,'Do you have to change your eye prescription regularly? Y/N');
: : : : : askquestion(screenname,'Do you have double vision? Y/N');
: : : : : cataractinference;
: : : : : end;
: : : : :
: : : : :
: : : : : so as you can see, it is very difficult in this lay out to be able to go back to a prv question...any suggestions?
: : : : :
: : : : :
: : : : Use a repeat-until loop around the askquestion() calls. Then using a case-of statement you can create the index method easily. This is not a very neat way to do, but it works. Example:
: : : :
: : : :   index := 0;
: : : :   screenname := 'Cataract Testing';
: : : :   repeat
: : : :     case index of
: : : :       0: askquestion(screenname,'Are you diabetic? Y/N');
: : : :       1: askquestion(screenname,'Do colours appear to be faded or dull? Y/N');
: : : :       2: askquestion(screenname,'Have you been overexposed to the sun in the past? Y/N');
: : : :       { Etc. }
: : : :       5: askquestion(screenname,'Do you have double vision? Y/N');
: : : :       else Exit; { Jump back to main menu }
: : : :     end;
: : : :   until index = 6 {number of questions };
: : : :   cataractinference;
: : : : 

: : : :
: : : :
: : :
: : :
: : :
: : : Thanks again for your help.
: : : however, I am getting unknown identifier at the beginign at index, whichi suppose means the word index needs to be declared some where before....
: : :
: : : what do i do.
: : :
: : : 2.) i see you removed the count function....i think i would need this function, becase remember, if you looked at my code, if a certain number of Y are met, it calls a procedure, else another output happens.
: : :
: : :
: : :
: :
: : ok i got it....i implemented the code, so it now looks like:
: :
: :
: : procedure cataractinference;
: : begin
: : 
: :     clrscr; pageheader('Cataract Testing - Inference');
: :     if count >=4 then
: :     begin
: :          gotoxy(20,10);writeln('suspect cataract');
: :          gotoxy(20,12);writeln('assign patient to cataract specialist');
: :          readln;
: :     end
: :     else
: :         uveitistest;
: : end;
: : 
: : 
: : procedure cataracttest;
: : begin
: :      count := 0;
: :      index:=0;
: :      repeat
: :      screenname := 'Cataract Testing';
: :      case index of    
: :      0: askquestion(screenname,'Are you diabetic? Y/N');
: :      1: askquestion(screenname,'Do colours appear to be faded or dull? Y/N');
: :      2: askquestion(screenname,'Have you been overexposed to the sun in the past? Y/N');
: :      3: askquestion(screenname,'Do lights appear to be too bright, or is there a halo around light? Y/N');
: :      4: askquestion(screenname,'Do you have to change your eye prescription regularly? Y/N');
: :      5: askquestion(screenname,'Do you have double vision? Y/N');
: :      else Exit;
: : end;
: : until index=6;     
: : cataractinference;
: : 
: : readln;
: : end;
: : 
: : 

: :
: : the program runs now...but when it comes to the first question which is
: : "are you diabetic Y/N"? and i enter any value..whether it be Y /or N or anything, the program just stays there and i have to use the ctrl break function to exit...but it used to work before.... *confused*
: :
: After each question, you should increase the index by 1 to go to the next question. Remember that the value stored in the Index variable determines which question the user gets to see, not the order in which the questions are coded.
:




 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.