Identify the errors in this C program (struct - calculating volume, area of cylinder). Explain.
#include <stdio.h>
#define PI 3.14
typedef struct cylinder{
float r,h;
float areacircle=2*PI*r;
float areacylinder;
float volumecylinder;
areacylinder=2*PI*r*h+2*PI*r*r;
volumecylinder=PI*r*r*h;
};
int main()
{
float start,numcyls;
printf("How many cylinders do you want? Enter a
positive integer.\n");
scanf("%f",&numcyls);
if(numcyls<1||ceilf(numcyls)!=numcyls)
while()
{printf("The number you have entered is not a positive
integer. Please try again.\n");
printf("Remember, you have been
asked to enter the number of cylinders you want.\n");
printf("Hence, you can only enter a
positive integer.\n");
scanf("%f",&numcyls);
if(numcyls>1&&ceilf(numcyls)==numcyls) break;
}
else
{for(start=1;start<=numcyls;start++)
{printf("Enter radius of
cylinder\n");
scanf("%f",&r);
printf("Enter
length of axis of cylinder\n");
scanf("%f",&h);
printf("The area
of the circular cross-section is: \n",areacircle);
printf("The
surface area of the cylinder is: \n",areacylinder);
printf("The
volume of the circular cross-section is: \n",volumecylinder);
return 0;
}
//Most of the erros are commented at their place, some main errors are trying to define area and volume inside struct which is //not possible in c and not creating struct and trying to call
//Missing math.h for ceil function, instead of ceilf, write
ceil
#include <stdio.h>
#include<math.h>
#define PI 3.14
typedef struct cylinder{
float r,h;
}cylinder;
float areacircle(float r){
//area of circle is Pi*r*r instead of 2*Pi*r
return PI*r*r;
}
float areacylinder(float r,float h){
return 2*PI*r*h+2*PI*r*r;
}
float volumecylinder(float r,float h){
return PI*r*r*h;
}
int main()
{
float start,numcyls;
printf("How many cylinders do you want? Enter a positive
integer.\n");
scanf("%f",&numcyls);
if(numcyls<1||ceil(numcyls)!=numcyls)
{
while(1)
{
printf("The number you have entered is not a positive integer.
Please try again.\n");
printf("Remember, you have been asked to enter the number of
cylinders you want.\n");
printf("Hence, you can only enter a positive integer.\n");
scanf("%f",&numcyls);
if(numcyls>1&&ceil(numcyls)==numcyls) break;
}
}
//change else part to checking for number of cylinders again
if(numcyls>1&&ceil(numcyls)==numcyls)
{
for(start=1;start<=numcyls;start++)
{
cylinder cylinde;
printf("Enter radius of cylinder %0.0f\n",start);
scanf("%f",&cylinde.r);
printf("Enter length of axis of cylinder %.0f\n",start);
scanf("%f",&cylinde.h);
printf("The area of the circular cross-section is: %f
\n",areacircle(cylinde.r));
printf("The surface area of the cylinder is: %f
\n",areacylinder(cylinde.r,cylinde.h));
printf("The volume of the circular cross-section is:%f
\n",volumecylinder(cylinde.r,cylinde.h));
printf("--------------------------------------------------------------------------------------");
}
}
//placing return 0 outside loop so that it wont stop program
return 0;
}//missing paranthesis
Identify the errors in this C program (struct - calculating volume, area of cylinder). Explain. #include...
I wrote a program which computes the area and perimeter of a square, circle, or rectangle. As you will see in my main function, there is a for loop in which the user is supposed to be able repeat the program until they enter "q" to quit. However, my program runs through one time, the prompt appears again, but then it terminates before the user is allowed to respond to the prompt again. I'm not able to debug why this...
So I have a question in regards to my program. I'm learning to program in C and I was curious about the use of functions. We don't get into them in this class but I wanted to see how they work. Here is my program and I would like to create a function for each of my menu options. I created a function to display and read the menu and the option that is entered, but I would like to...
i need help converting this code to java please
#include<stdio.h>
typedef struct{
int pid,at,bt,ct,tat,wt,f;
}process;
int main()
{
int n,i,j,st=0,c,tot=0,pno=0,swi=0;
float atat=0,awt=0;
printf("enter no of processes : ");
scanf("%d",&n);
process a[n],temp;
for (i=0;i<n;i++){
a[i].pid=i+1;
a[i].f=0;
printf("enter at : ");
scanf("%d",&a[i].at);
printf("enter the bt : ");
scanf("%d",&a[i].bt);
printf("--------------------------- ");
}
while(1){
int min=999,c=n;
if (tot==n)
break;
for (i=0;i<n;i++){
if
((a[i].at<=st)&&(a[i].f==0)&&(a[i].at<min)){
min=a[i].at;
c=i;
}
}
if(pno!=a[c].pid)
swi++;
if (c==n)
st++;
else{
a[c].ct=st+a[c].bt;
st=st+a[c].bt;
a[c].tat=a[c].ct-a[c].at;
atat=atat+a[c].tat;
a[c].wt=a[c].tat-a[c].bt;
awt=awt+a[c].wt;
a[c].f=1;
tot++;
}
}
printf("...
NEED CODE HELPS WITH C PROGRAMMING. ISSUES EXPLAINED IN BOLD. COMPARING TWO LETTERS AND CALLING A FUNCTION. Problem are explained in bold #include <stdio.h> #include <string.h> #include <stdlib.h> #define pi 3.1415 void Area (double n); void VolSphere (double n); void Circumference (double n); void AllCalc (); // i dont know if the declaration of the function is correct AllCalc = AllCalculations //function main begins program execution int main (void) { puts("-Calculating Circle Circumference, Circle Area or Sphere Volume-\n"); void (*f[4])...
Please do this in C language. Thank you
1. Write the following functions that compute the volume and surface of a sphere with radius r; a cylinder with circular base with radius r and height h; and a cone with circular base with radius r and height h. Place these functions in appropriate class. Define n (PI) as a constant variable equals to 3.14 then use it in the functions. float sphereVolume(float r) float sphereSurface(float r) float cylinderVolume(float r, float...
Write a complete C program. Define a structure type element_t to represent one element from the periodictable of elements. Components should include the atomic number (aninteger); the name, chemical symbol, and class (strings); a numeric field forthe atomic weight; and a seven-element array of integers for the number ofelectrons in each shell. The following are the components of an element_t structure for sodium.11 Sodium Na alkali_metal 22.9898 2 8 1 0 0 0 0 Have the user enter the data...
Write a C++ program to compute the total volume of N cones, where N is a number entered by the user. Repeat the request for N until the user enters a positive number. For each cone, ask for the radius and height, compute the volume, and add that volume to the total. Each time you ask the user to enter either the height or the radius, if the user does not enter a positive number, display an error message and...
Exercise 5.5 (EASY) for beginning CS CLASS PART A Copy or cut and paste program P5_2.cpp (located below) to a new program called ex55.cpp. Make PI a constant value. Compile and run the program for the following values: r = 2 cm, h = 10 cm The correct answer should be: The cross-section area of the cylinder is 3.89556 inch-sq The side area of the cylinder is 19.4778 inch-sqr Did you get the correct answer? You didn't! Explain...
Need help for C program. Thx #include <stdio.h> #include <string.h> #include <ctype.h> // READ BEFORE YOU START: // This homework is built on homework 06. The given program is an updated version of hw06 solution. It begins by displaying a menu to the user // with the add() function from the last homework, as well as some new options: add an actor/actress to a movie, display a list of movies for // an actor/actress, delete all movies, display all movies,...
Program Description Write a program that calculates the distance between two places on Earth, based on their latitude and longitude. Prompt the user to enter the latitude and longitude of two places. The Earth’s mean radius is to be taken as 6371.01 km. Use user-defined variables with descriptive names wherever necessary. Following steps will have to be followed: Program must have header comments stating the author of the Program, date, and Program Description. Include the math.h header file Initialize a...