+3 votes

#include <stdio.h>

#include <math.h>

int main()

{

double x, y, z, m, r;

double costMilk, costpaint;

printf("enter height of drum(in cms):");

scanf("%lf", x);

printf("enter lower radius(in cms):");

scanf("%lf", y);

printf("enter upper radius(in cms):");

scanf("%lf", z);

printf("enter cost of milk(per litre):");

scanf("%lf", m);

printf("enter cost of paint required for 1 sqcm:");

scanf("%lf", r);

costMilk = (((1/3)*(22/7)*x*(y*y + y*z + z*z))*(1/1000))*(m);

printf("the total cost of milk that fills the drum is:%f" , costMilk);

costpaint = ((22/7)*(y + z)*sqrt((z-y)*(z-y) + x*x))*r;

printf("the total cost of painting the drum is:%f" , costpaint);

return 0;

}

#include <math.h>

int main()

{

double x, y, z, m, r;

double costMilk, costpaint;

printf("enter height of drum(in cms):");

scanf("%lf", x);

printf("enter lower radius(in cms):");

scanf("%lf", y);

printf("enter upper radius(in cms):");

scanf("%lf", z);

printf("enter cost of milk(per litre):");

scanf("%lf", m);

printf("enter cost of paint required for 1 sqcm:");

scanf("%lf", r);

costMilk = (((1/3)*(22/7)*x*(y*y + y*z + z*z))*(1/1000))*(m);

printf("the total cost of milk that fills the drum is:%f" , costMilk);

costpaint = ((22/7)*(y + z)*sqrt((z-y)*(z-y) + x*x))*r;

printf("the total cost of painting the drum is:%f" , costpaint);

return 0;

}

0 votes

In scanf(), the additional arguments should be pointers. The & (address of) operator will return the address that points to your variable. See the example shown by *abc*.

First of all, I was scratching my head why you have 22/7 in your code. I searched the web a bit and found out why. Still, it doesn't make much sense to me. If you want PI, then write PI, not an expression that only approximates it and may be confusing for many. You can create our constant or macro and use that instead.

#define PI 3.14159265359

First of all, you're talking about a cylinder, but you ask for lower and upper radius. For a cylinder, it's the same. When it is different, it is a truncated cone or conical frustum, which is the tip of a cone cut off.

The volume of the truncated cone is the volume of the larger cone reduced by the volume of the smaller cone.

V_{total} = V_{large} - V_{small }= PI/3 * h_{large} * r_{large}^{2} - PI/3 * h_{small} * r_{small}^{2}

The area should be calculated similarly, the difference of lateral surface areas plus the two bases.

I have to leave now and I don't have time to finish the maths.

You can find the proper formula on the linked site above.

Note: I believe you have been using the very (or similar) site, but you were using the formula of the square frustum, not the conical frustum.

...