Jump to content

Procedures

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
16 replies to this topic

#1
sobi

sobi

    Newbie

  • Members
  • Pip
  • 9 posts
Again working on this problem involving procedures in pascal. It says to write an interactive pascal program to calculate the volume and surface area of a cylinder, given the radius and the length. One procedure is to be used to calculate the volume and another procedure to calculate the length.
Formula for calculating volume: πr^2L(ie Pi *R*R*L) and surface area: 2#R(L+R)
ie : 2*Pi*R(L+R).
Here is my code so far, not getting exactly what i want.


PROGRAM Compute_Volume (Output);

CONST

    Pi = 3.142;

PROCEDURE Compute_Volume_of_Cylinder (VAR Radius, Pi, Length, Volume_of_Cylinder:

          Real);


          BEGIN

          Writeln('Enter the radius of the cylinder.');

          Readln(Radius);

          Writeln('Enter the length of the cylinder.');

          Readln(Length);

          Volume_of_cylinder := Pi * Radius * Radius * Length;

          Writeln('Volume_of_Cylinder: ', Volume_of_Cylinder);

          Readln();

          END;

PROCEDURE Compute_Surface_Area (VAR Radius, Surface_area_of_cylinder, Length:

          Real);

          BEGIN

          Writeln('Enter the radius of the cylinder.');

          Readln(Radius);

          Writeln('Enter the length of the cylinder.');

          Readln(Length);

          Surface_area_of_cylinder := 2 * Pi * Radius *( Length + Radius);

          Writeln('Surface_area_of_cylinder: ', Surface_area_of_cylinder);

          Readln();

          END;


BEGIN

Writeln('This must work');

Readln();

Writeln('Compute volume of cylinder');

Readln();













  END.



#2
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
What's the question?
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#3
sobi

sobi

    Newbie

  • Members
  • Pip
  • 9 posts
The questions is: Write an interactive pascal program to
calculate the volume and surface area of a cylinder, given the radius and the length. One procedure is to be used to calculate the volume and another procedure to calculate the length.
Formula for calculating volume: πr^2L(ie Pi *R*R*L) and surface area: 2#R(L+R)
ie : 2*Pi*R(L+R).

#4
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
No. You have code, what is your question about getting the code from its current state to the solution?
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#5
sobi

sobi

    Newbie

  • Members
  • Pip
  • 9 posts
It is not giving me the value of the volume and surface area as is intended by the program. I am not even seeing any of the writelns in the procedure displayed when i run the program.The only writeln i am seeing is the one outside the procedures. i must be missing something.

#6
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
You aren't calling the functions.
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#7
sobi

sobi

    Newbie

  • Members
  • Pip
  • 9 posts
Not quite sure about calling the functions, can you put me through on this?

#8
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
You need a BEGIN END. pair for the main body of your program. Don't you know how to call functions?
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#9
sobi

sobi

    Newbie

  • Members
  • Pip
  • 9 posts
Ok, not exactly sure on what to do again on this. Inserted the Begin/End pair in the main body of the program to call the functions. I'm now having an error. This is what i have:
(* This Program calculates and prints the diameter, the circumference,
or the area of a circle, given the radius *)

PROGRAM Computes (Volume, Surface_Area);
CONST
    Pi = 3.142;
VAR
   Radius, Length, Voloume_of_cylinder, Surface_area_of_cylinder:
           Real;

PROCEDURE Compute_Volume_of_Cylinder (VAR Radius, Pi, Length, Volume_of_Cylinder:
          Real);

          BEGIN
          Writeln('Enter the radius of the cylinder.');
          Readln(Radius);
          Writeln('Enter the length of the cylinder.');
          Readln(Length);
          Volume_of_cylinder := Pi * Radius * Radius * Length;
          Writeln('Volume_of_Cylinder: ', Volume_of_Cylinder);
          Readln();
          END;
PROCEDURE Compute_Surface_Area (VAR Radius, Surface_area_of_cylinder, Length:
          Real);
          BEGIN
          Writeln('Enter the radius of the cylinder.');
          Readln(Radius);
          Writeln('Enter the length of the cylinder.');
          Readln(Length);
          Surface_area_of_cylinder := 2 * Pi * Radius *( Length + Radius);
          Writeln('Surface_area_of_cylinder: ', Surface_area_of_cylinder);
          Readln();
          END;


begin
     Computes ;
     Compute_Volume_of_Cylinder ;
     Compute_Surface_Area ;

end.


#10
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
You have to pass the parameters in the procedure calls.
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#11
Amonijack

Amonijack

    Learning Programmer

  • Members
  • PipPipPip
  • 56 posts
where are the variables which you declared in function ?
PROCEDURE Compute_Surface_Area (VAR Radius, Surface_area_of_cylinder, Length:
you miss ) in the end of this.
calling procedure :
name(variables);

#12
tibumm

tibumm

    Newbie

  • Members
  • Pip
  • 1 posts
yeah