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.
What's the question?
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).
No. You have code, what is your question about getting the code from its current state to the solution?
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.
You aren't calling the functions.
Not quite sure about calling the functions, can you put me through on this?
You need a BEGIN END. pair for the main body of your program. Don't you know how to call functions?
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.
You have to pass the parameters in the procedure calls.
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks