In: Computer Science
In this program, there are 3 bugs and 2 syntax errors. Please identify them! The source code is below.
The source code is in C:
/*------------------------------------------------------------------
File: CylinderVolume.c (Lab 3)
Author: Gilbert Arbez, Fall 2018
Description: Calculates how the volume changes for different depths
in a horizontal cylinder.
------------------------------------------------------------------*/
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
// Define symbolic constant
#define N 50 // number of points to compute
#define TRUE 1
#define FALSE 0
// Prototypes
void computeDisplayVolume(double, double);
/*--------------------------------------------------------------------
Function: main
Description: Gets from the user the radius and length of the cylinder,
calls computeDisplayVolume to compute and display a table
of how the volume changes with depth of a liquid in
the cylinder.
----------------------------------------------------------------------*/
void main()
{
// Variable declarations
double radius; // cylinder radius
double length; // cylinder length
int flag; // sentinelle for controlling data input
// Get input from user, the cylinder radius and length
do
{
flag = TRUE;
printf("Please give cylider radius and length: ");
scanf("%lf %lf",&radius, &length);
if(radius <= 0.0 || length <= 0.0)
{
printf("Both values must be greater than zero.\n");
flag = FALSE;
}
} while(flag == TRUE)
// Compute/display depth/volume data
computeDisplayVolume(radius, length);
}
/*------------------------------------------------------------------------
Function: computeDisplayVolume
Parameter
radius - radius of the horizontal cylinder
length - length of the horizontal cylinder
Description: Computes and displays depth/volume data points in a table
that varies the depth of the liquid from 0 to the cylinder diameter.
N such data points are computed (i.e. the increment in the
value of h is 2r/N).
------------------------------------------------------------------------*/
void computeDisplayVolume(double radius, double length)
{
// Declaration of variables
double increment; // how to increment the depth
double h; // depth value
double volume; // volume value
int i ; // loop counter
// setup the variables
increment = radius/N;
h = 0.0;
// Table Header
printf("The change in liquid volume of the cylinder with radius %.2f \nand length %.2f as depth changes is as follows.\n",
radius, length);
printf("%10s %10s\n","Depth", "Volume");
printf("------------------------\n");
// Loop for calculating each of the n depth/volume points.
for(i = 0 i < N; i = i + 1)
{
volume = pow(radius,2)*acos((radius-h)/radius);
volume = volume - (radius - h)*sqrt(2.0*radius*h - pow(h,2));
volume = volume*length;
// Display the row with ocmputed values
printf("%10.2f %10.2f\n", h, volume);
}
}
C PROGRAM ===>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
// Define symbolic constant
#define N 50 // number of points to compute
#define TRUE 1
#define FALSE 0
// Prototypes
void computeDisplayVolume(double, double);
/*--------------------------------------------------------------------
Function: main
Description: Gets from the user the radius and length of the cylinder,
calls computeDisplayVolume to compute and display a table
of how the volume changes with depth of a liquid in
the cylinder.
----------------------------------------------------------------------*/
void main()
{
// Variable declarations
double radius; // cylinder radius
double length; // cylinder length
int flag; // sentinelle for controlling data input
// Get input from user, the cylinder radius and length
do
{
flag = TRUE;
printf("Please give cylider radius and length: ");
scanf("%lf %lf",&radius, &length);
if(radius <= 0.0 || length <= 0.0)
{
printf("Both values must be greater than zero.\n");
flag = FALSE;
}
else
{
// Compute/display depth/volume data
computeDisplayVolume(radius, length);
}
} while(flag == TRUE);
}
/*------------------------------------------------------------------------
Function: computeDisplayVolume
Parameter
radius - radius of the horizontal cylinder
length - length of the horizontal cylinder
Description: Computes and displays depth/volume data points in a table
that varies the depth of the liquid from 0 to the cylinder diameter.
N such data points are computed (i.e. the increment in the
value of h is 2r/N).
------------------------------------------------------------------------*/
void computeDisplayVolume(double radius, double length)
{
// Declaration of variables
double increment; // how to increment the depth
double h; // depth value
double volume; // volume value
int i ; // loop counter
// setup the variables
increment = 2*radius/N;
h = 0.0;
// Table Header
printf("The change in liquid volume of the cylinder with radius %.2f \nand length %.2f as depth changes is as follows.\n",
radius, length);
printf("%10s %10s\n","Depth", "Volume");
printf("------------------------\n");
// Loop for calculating each of the n depth/volume points.
for(i = 0 ; i < N; i = i + 1)
{
volume = pow(radius,2)*acos((radius-h)/radius);
volume = volume - (radius - h)*sqrt(2.0*radius*h -
pow(h,2));
volume = volume*length;
h = h+increment;
// Display the row with ocmputed values
printf("%10.2f %10.2f\n", h, volume);
}
printf("\n");
}
OUTPUT SCREENSHOT ===>