Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

i am trying to write a code for my school home work but it shows an error

+3 votes
asked May 24 by David (150 points)
#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;

}

2 Answers

0 votes
answered Oct 8 by abc (140 points)

in scanf use & before variable

i.e.

scanf("%lf", &x);

instead of

scanf("%lf", x);

Enjoy :)

0 votes
answered Oct 8 by Peter Minarik (34,450 points)

The programming part

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.

The mathematics part

PI vs 22/7

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

Volume

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.

Vtotal = Vlarge - Vsmall = PI/3 * hlarge * rlarge2 - PI/3 * hsmall * rsmall2

Area

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.

Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...