Closed Thread
Page 1 of 2 12 LastLast
Results 1 to 10 of 17

Thread: Procedures

  1. #1
    sobi is offline Newbie
    Join Date
    Apr 2009
    Posts
    9
    Rep Power
    0

    Procedures

    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.

    Code:
    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. CODECALL Circuit advertisement
    Join Date
    Always
    Posts
    Many

     
  3. #2
    Join Date
    Jul 2006
    Posts
    16,489
    Blog Entries
    75
    Rep Power
    143

    Re: Procedures

    What's the question?
    Programming is a branch of mathematics.
    My CodeCall Blog | My Personal Blog

  4. #3
    sobi is offline Newbie
    Join Date
    Apr 2009
    Posts
    9
    Rep Power
    0

    Re: Procedures

    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).

  5. #4
    Join Date
    Jul 2006
    Posts
    16,489
    Blog Entries
    75
    Rep Power
    143

    Re: Procedures

    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

  6. #5
    sobi is offline Newbie
    Join Date
    Apr 2009
    Posts
    9
    Rep Power
    0

    Re: Procedures

    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.

  7. #6
    Join Date
    Jul 2006
    Posts
    16,489
    Blog Entries
    75
    Rep Power
    143

    Re: Procedures

    You aren't calling the functions.
    Programming is a branch of mathematics.
    My CodeCall Blog | My Personal Blog

  8. #7
    sobi is offline Newbie
    Join Date
    Apr 2009
    Posts
    9
    Rep Power
    0

    Re: Procedures

    Not quite sure about calling the functions, can you put me through on this?

  9. #8
    Join Date
    Jul 2006
    Posts
    16,489
    Blog Entries
    75
    Rep Power
    143

    Re: Procedures

    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

  10. #9
    sobi is offline Newbie
    Join Date
    Apr 2009
    Posts
    9
    Rep Power
    0

    Re: Procedures

    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:
    Code:
    (* 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.

  11. #10
    Join Date
    Jul 2006
    Posts
    16,489
    Blog Entries
    75
    Rep Power
    143

    Re: Procedures

    You have to pass the parameters in the procedure calls.
    Programming is a branch of mathematics.
    My CodeCall Blog | My Personal Blog

Closed Thread
Page 1 of 2 12 LastLast

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Coding Procedures...
    By veda87 in forum C Tutorials
    Replies: 1
    Last Post: 11-22-2009, 12:21 AM
  2. If,Switches, and Spaceport docking procedures
    By Drago795 in forum C and C++
    Replies: 7
    Last Post: 10-18-2009, 11:28 AM
  3. SQL Triggers and Stored Procedures
    By Amy in forum Database & Database Programming
    Replies: 7
    Last Post: 12-18-2008, 01:41 AM
  4. Prohibiting executable statements outside procedures
    By ozmo in forum Visual Basic Programming
    Replies: 3
    Last Post: 12-08-2008, 05:25 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts