Question
Need help getting code to work properly. I am coding in C. This is my current code: /* * Computing the Weight of a Batch
Need help getting code to work properly. I am coding in C. This is my current code:
/* * Computing the Weight of a Batch of Flat Washers */
#include
int main(void) {
/* * Pointers */ float *innerradius = (float*) malloc(sizeof(float)); /* input - radius of a inner circle */ float *outerradius = (float*) malloc(sizeof(float)); /* input - radius of outer circle */ float *idiameter = (float*) malloc(sizeof(float)); /* diameter of inner circle */ float *odiameter = (float*) malloc(sizeof(float)); /* diameter of outer circle */ float *rimarea = (float*) malloc(sizeof(float)); /* area of a rim */ float *matden = (float*) malloc(sizeof(float)); /* input - density of material in grams/cm^3 */ float *thickness = (float*) malloc(sizeof(float)); /* input - thickness of material in centimeters */ float *weight = (float*) malloc(sizeof(float)); /* weight of a single washer */ int *quantity = (int*) malloc(sizeof(int)); /* number of washers */ float *batch = (float*) malloc(sizeof(float)); /* weight of a batch of washers */ /* * Calculating the radius of both the inner and outer circles */
printf("Enter the inner diameter> "); scanf("%f ", idiameter);
printf("Enter the outer diameter> "); scanf("%f ", odiameter);
*innerradius = *idiameter / 2.0; *outerradius = *odiameter / 2.0;
printf("The inner radius is %f ", *innerradius); printf("The outer radius is %f ", *outerradius);
/* * Calculating the area of the rim */
*rimarea = PI * *outerradius * *outerradius-PI * *innerradius * *innerradius;
printf("Area of the flat washer is %f ", rimarea);
/* * Finding material density and thickness */
printf(" Enter the density of the material in grams/cm cubed "); scanf("%f",matden);
printf(" Enter the thickness of the flat washer "); scanf("%f",thickness);
/* * Finding the weight of a single flat washer */
*weight = *rimarea * *matden * *thickness;
printf("Weight of a single flat washer is %f ",weight);
/* * Finding the weight of a batch of flat washers */
printf("Number of flat washers in a batch - "); scanf("%d ",quantity);
*batch = *weight * *quantity;
/* * Displaying the weight of the batch of washer */
printf(" The weight of the batch of washers is %f grams ",batch); free(innerradius); free(outerradius); free(idiameter); free(odiameter); free(rimarea); free(matden); free(thickness); free(weight); free(quantity); free(batch); return (0); }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started