Could you mind telling me what can I do for the following question?

To write a skeleton program for the assignment. It should have a menu system with at least 5 options. The menu keeps repeating after each procedure is called. When one of the procedures is called just return a message to the screen saying what this procedure will do: ie “this is task 1”

The menu options are:
1 Task 1
2 Task 2
3 Task 3
4 Task 4
0 Exit menu system


(Hint: use a case statement)


Cheers,

Dani AI

Generated

's example already gives a correct, working skeleton: a repeating menu, a case dispatch, and stub procedures. A few small refinements make that pattern more robust and easier to reuse: validate input so letters or empty lines don't confuse the program, avoid mixing low-level input calls (which can leave stray characters in the buffer), and use a portable way to pause/clear the screen if the environment supports it.

Read a whole line and parse it instead of reading directly into an integer. The val routine is simple and portable:

var
  line: string;
  code, err: Integer;
begin
  readln(line);
  val(line, code, err);
  if err <> 0 then
    writeln('Please enter a valid number.')
  else
    choice := code;

If your compiler provides TryStrToInt (SysUtils), it is even cleaner:

uses SysUtils;
var
  line: string;
  code: Integer;
begin
  readln(line);
  if not TryStrToInt(line, code) then
    writeln('Invalid input.')
  else
    choice := code;

Quick practical tips: keep each task procedure tiny (print the stub message and return), centralize the menu display in one procedure, use a named constant or an enumerated type for valid options, and use clrscr/ReadKey from crt only when you know the target compiler supports it. Validate the parsed integer against the allowed range before dispatching in the case. These changes preserve the simplicity of the assignment while avoiding common runtime surprises.

I tryed to explain everything.....

program solution;

var choice:Integer;{the user choice}
{
let's create the 5 procedures
these procedures does nothing,only
called by the main program...
}


{0,}
procedure task_zero;
begin
     writeln('0. procedure is exiting from the main program...');
     writeln('press enter to continue...');
end;

{1,}
procedure task_one;
begin
     writeln('1. procedure is running...');
     writeln('press enter to continue...');
     readln;
end;

{2,}
procedure task_two;
begin
     writeln('2. procedure is running...');
     writeln('press enter to continue...');
     readln;
end;

{3,}
procedure task_three;
begin
     writeln('3. procedure is running...');
     writeln('press enter to continue...');
     readln;
end;

{4,}
procedure task_four;
begin
     writeln('4. procedure is running...');
     writeln('press enter to continue...');
     readln;
end;
{
ok,the procedures are made,so call them in the main program
used the case statement.... 'till the user presses the zero
}
begin
     repeat
     {
     let's write the menu to the screen
     }
     writeln('MENU OPTIONS ARE:');
     writeln('0. Exit Menu system');
     writeln('1. Task one');
     writeln('2. Task two');
     writeln('3. Task three');
     writeln('4. Task four');

     {
     ask a number from the user,from zero to four (0..4)
     }
     writeln('Select a number between 0 and 4.');
     write('Your choice is: ');
     readln(choice);{here,catch the answer...}
     writeln;
     {
     and last,analyze the variable's value..
     }
     case (choice) of
     0:begin
          task_zero; {call them by its name!}
          writeln;
       end;
     1:begin
          task_one;
          writeln('Procedure ended.');
          writeln;
       end;
     2:begin
          task_two;
          writeln('Procedure ended.');
          writeln;
       end;
     3:begin
          task_three;
          writeln('Procedure ended.');
          writeln;
       end;
     4:begin
          task_four;
          writeln('Procedure ended.');
          writeln;
       end;
     else writeln('please,between 0 and 4.');
     end;{of case}

     until choice = 0;


     readln;
end.
{
created by FlamingClaw 2009.08.27.
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.