re : main-->procedure coomunication + Menu Procedure 
Author Message
 re : main-->procedure coomunication + Menu Procedure

Hi

I have implemented some of the suggestions made in a modified way so that
the program works now, and I understand how to pass Varaible values from
Main to a procedure, and even procedure to procedure. I even found a cool
trick to make our program end quickly when the user chooses to do so usinh

halt;

an example of its implementation is in the DetermineAction part of my
program below: (the rest of the program is there too, so if anyone wants to
make design or error checking suggestions feel free to).

NOTE THAT: the procedures for menu choices 2,3,4 and 5 still have to be
written, so for the moment a menu choice of 2,3,4 or 5 is just a simple
WRITELN of what that choice does.

PROGRAM SocogDiving (INPUT,OUTPUT);
uses crt;

VAR
  UserOptionError: Boolean;{flag to indicate whether I/O is OK or not}
  ExitChoice,              {shows whether user has chosen to exit}
  UserOption : Integer;    {stores the menu option chosen by the user}

{-------------------------------------------------------------}

PROCEDURE Instructions;

BEGIN {Instructions}
  WRITELN ('This program automates the scoring process of a diving');
  WRITELN ('competition. It allows entry of the competitors names');
  WRITELN ('and the raw scores awarded to them. Corrected scores');
  WRITELN ('for each individual dive are then displayed. After all');
  WRITELN ('dives are completed the competitors total scores will be');
  WRITELN ('listed in diving order or displayed in ranking, highest');
  WRITELN ('to lowest.'                                             );
  WRITELN;
  WRITELN ('To use the program choice ''2. Enter Competition Results''
must');
  WRITELN ('be chosen first, and the onscreen instructions followed.');
  WRITELN;
  WRITELN ('This must be followed by choice ''3. Enter Scores'', whose');
  WRITELN ('on screen instructions must also be followed.');
  WRITELN;
  WRITELN ('After these choices have been made, either choice 4 or');
  WRITELN ('choice 5 can be made to display the results in diving');
  WRITELN ('order or descending order by corrected scores');
  WRITELN;
  WRITELN ('The program can be exited when the main menu is shown by');
  WRITELN ('choosing choice ''6. Exit''');

END; {Instructions}

{-------------------------------------------------------------}
PROCEDURE DetermineAction (UserOption : Integer; {stores the users option}
                           ExitChoice: Integer); {stores whether the user
wanst to exit}
{VAR
  Option2Done,
  Option3Done : Boolean;}

BEGIN {DetermineAction}
  clrscr;
  CASE UserOption OF {Depending on the option chosen, the
                  appropriate action to be done is exexcuted}

    1 : BEGIN
        clrscr;
        Instructions;
        READLN;
        clrscr;
        END;
    2 : WRITELN ('Run DiverDetails');          {DiverDetails}
    3 : WRITELN ('Run Scores');                {Scores}
    4 : WRITELN ('Run Display Results');       {DisplayResults}
    5 : WRITELN ('Run Determine Placings');    {DeterminePlacings}
    6 : BEGIN
    WRITELN ('Are you sure you want to exit the program (Enter 1 for Yes, 0
for No)?');
    READLN(ExitChoice);
    IF Exitchoice=1 THEN
      halt;
    END;

  END; {case}

END; {DetermineAction}

{-------------------------------------------------------------}

PROCEDURE Menu (VAR ChosenOption : Integer); {stores the chosen option}

BEGIN {Menu}
 REPEAT
  REPEAT {displaying the menu and validating input}

    WRITELN;
    WRITELN ('1. Instructions');
    WRITELN ('2. Enter Competition Details');
    WRITELN ('3. Enter Scores');
    WRITELN ('4. Display Unsorted Results');
    WRITELN ('5. Display Placings');
    WRITELN ('6. Exit');
    WRITELN;
    textcolor(red+blink);
    WRITELN ('Please make a selection from choices 1 to 6');
    textcolor(blue);
    {$I-}                            {turns error checking off}
    READLN(ChosenOption);            {does I/O operation}
    {$I+}                            {turns error checking back on}

    UserOptionError := ioresult <> 0; {ioresult is a system variable that
                                     automatically receives a numeric value
                                     as a result of the I/O, 0 if OK, non
                                     zero otherwise}

    IF UserOptionError OR (ChosenOption<1) OR (ChosenOption>6) THEN {if any
sort of error}
      BEGIN
        WRITELN ('Invalid entry. Press any key to view the menu again');
        READLN;
      END;

  UNTIL (ChosenOption >=1) AND (ChosenOption <= 6 ); {do until no error}
DetermineAction(UserOption,ExitChoice);
UNTIL Exitchoice=1;

END; {Menu}

{-------------------------------------------------------------}

BEGIN {Socog Diving}
textcolor(blue);
textbackground(white);

  UserOption := 0;
  ExitChoice := 0;
  clrscr;

  Instructions;
  WRITELN;
  textcolor(red+blink);
  WRITELN('Press Enter to continue');
  textcolor(blue);
  READLN;

  clrscr;
  Menu(UserOption);
  textcolor(white);
  textbackground(black);
  readln;
  clrscr;
END. {Socog Diving}



Wed, 18 Jun 1902 08:00:00 GMT  
 
 [ 1 post ] 

 Relevant Pages 

1. passing a result form procedure-->Main program

2. Help needed re: Menu Procedure

3. System Menu Click Procedure???

4. Calling a procedure within a procedure

5. HELP - calling a Procedure from with a Procedure??

6. Using a Procedure within a Procedure?

7. Procedure as parameter in procedure

8. Fast PutCharacter Procedure &/or remove cursor procedure

9. fast putchar procedure and remove cursor procedure needed for lord II type game

10. passing procedures as arguments for another procedure in Turbo pascal

11. passing procedures as arguments for another procedure in Turbo pascal

12. passing procedures as arguments for another procedure in Tu

 

 
Powered by phpBB® Forum Software