Hello Everyone,
This question is quite hard for me to understand it. I have gone this further. your help will be appreciated. The program is used to calculate volumes of tanks.

#include <stdio.h>
#include <stdlib.h>
#define PI 3.14152

/*Declare for storing the data of a cylindrical tank
new structure type named TANK with real-valued components
Diameter and height*/

typedef struct Tank{
    float Diameter;
    float Height;
} TANK;

/*Diameter and height of a tank should be read from the keyboard.
complete the stated C function named
inputTank that reads the diameter and height of real-valued, in a
Structure variables of type TANK stores and returns it*/

TANK inputTank();

??? inputTank()
{
    Tank t;

    printf("\nPlease Enter the data of the Tank...\n");
    printf("Diameter (m):\t");
    scanf("%f",&t.diameter);
    printf("Height (m):\t\t");
    scanf("%f",&t.height);
    ???;
}

/*The volume of a cylindrical tank with diameter d and height h
is calculated according to the formula V = π * d2 * h / 4. Create a function called getVolume,
leading to a transferred structure variables of type TANK the real-valued volume
calculates and returns as Given in prototype below */
float getVolume(TANK);

float getVolume()
{
    float Volume;
    Volume= PI * TANK.diameter * TANK.diameter * TANK.height/4;
    return Volume;
}

/* Define a field called tanks with 10 elements of type TANK!*/
/* Read the data of the 10 tanks (height and diameter) of the field
tank using the function called input tank from the above function inputTank
one at a time from the keyboard*/
/* Calculate the volume for each tank the respective volume using the
Function called getVolume and print it together with the number of the tanks, starting with one (1, 2, 3 ... 10)
on the Screen! Calculate further the sum total of all
Volumes and print it finally (as "Total") on the screen*/

int main(void)
{
???tanks???;
float sum, volume;
int i;

/*Input of the individual tanks*/
for(???) {
???;
}

printf("\nTabelle aller Tank-Volumen:\n"); /*List of the tank volume*/

to be filed;
for(???) {
???;
printf("Tank %i:\t",???);
printf("%.1f m^3\n",???);
sum ???;
}

printf("\nTotal: %.1f m^3\n",???); /*Total sum of volumes*/

return 0;
}

Let's start at the top. You should be able to figure out line 21 given line 19. After you've figured out line 21, line 30 should be easy (line 17 explains what line 30 needs to do).

For lines 39 to 44, "TANK" is not a variable (it's a structure). Given the following example, you should be able to fix this:

/* This function consumes two integers, and returns the sum. */
int sum(int a, int b)
{
    return a * b;
}

Before you worry about trying to get 10 tanks working, just try to get one working.

At line 57, you'll need to create an array of 10 tanks. Then you'll need to get the dimentions of the 10 tanks (lines 62-63).

I have no idea what line 68 is, but it sure aint c. 69 is just iterating through the tanks, 70 is calculating the volume and 73 is accumulating the sum.

Sometimes looking at some similar problem code examples can give you ideas how to get started ...

Suppose you had a Money struct ...

typedef struct
{
    unsigned dollars;
    unsigned cents;

} Money ;

And you wanted to code a function to take in data from a keyboard user to fill up this struct ...

You could code that like this ...

Money takeInMoney()
{
    Money m;
    m.dollars = takeInValid( "Enter dollars : " );
    m.cents   = takeInValid( "Enter cents   : " );

    if( m.cents >= 100 ) /* normalize */
    {
        m.dollars += m.cents / 100;
        m.cents %= 100;
    }

    return m;
}

Of couse, you would have to have already definded this function, before you could call it ...

/* a simple student way to handle numeric input ...
   so program won't crash on bad input */
unsigned takeInValid( const char* msg )
{
    unsigned val = 0;
    while( 1 ) /* loop forever until break is reached ... */
    {
        printf( msg ); fflush( stdout );

        if( scanf( "%u", &val ) == 1 && getchar() == '\n' )
            break;
        else
        {
            printf( "\nUnsigned integer input only here please ...\n" );
            while( getchar() != '\n' ) ; /* flush stdin ... */
        }
    }
    return val;
}

Now if you wished to sum up an array of 'Money' type values, that could be handled like this:

Money sumAll( const Money deposits[], unsigned size )
{
    Money tot = { 0, 0 };
    unsigned i;
    for( i = 0; i < size; ++i )
    {
        tot.dollars += deposits[i].dollars;
        tot.cents += deposits[i].cents;
    }

    if( tot.cents >= 100 ) /* normalize */
    {
        tot.dollars += tot.cents / 100;
        tot.cents %= 100;
    }

    return tot;
}

And if you needed to find the average Money value in an array of Money ...

Money getAverage( const Money* total, unsigned num )
{
    Money m_avg = { 0, 0 };
    double avg_cents = total->dollars*100 + total->cents;
    double avg_dols;

    if( num == 0 ) return m_avg;


    /* if reach here, NO danger of dividing by zero ... */

    avg_cents /= num; /* a double for the average total (in cents) deposit */

    avg_dols = avg_cents / 100; /* convert ALL cents to dollars.cents */

    m_avg.dollars = (int) avg_dols;

    /* now subtract any integer part ... */
    avg_dols -= m_avg.dollars;

    /* gets cents part  ... *100 + .5 to round to nearest int */
    m_avg.cents = (int)(avg_dols*100 + .5);

    return m_avg;
}

Of course you could code a function to print out Money ...

/* passing in an address to save making copy */
void printMoney( const Money* m )
{
    printf( "$%d.%02d", m->dollars, m->cents );
}

Then in main, you could do something like this ...

    Money deposits[MAX_NUM_DEPOSITS]; /* get space in memory ... */
    Money total;
    Money average;

    do 
    {
        unsigned size = 0;
        printf( "New customer %s ...\n", NAMES[size] );
        /* keep looping while more 'customers' with deposits ... */
        while( tolower( takeInChr( "Do you have a "
                                   "deposit (y/n) ? " )) != 'n' )
        {
            deposits[size] = takeInMoney();
            ++size;
            if( size == MAX_NUM_DEPOSITS )
            {
                printf( "You have reached, %d, the "
                        "max number of deposits allowed today.",
                         MAX_NUM_DEPOSITS );
                break; /* exit the while loop right now ... */
            }
            printf( "New customer %s ...\n", NAMES[size] );
        }

        total = sumAll( deposits, size );
        printf( "\nThe total on deposit is: " );
        printMoney( &total );

        average = getAverage( &total, size );
        printf( "\nThe average of the %d deposits was: ", size );
        printMoney( &average );

        puts( "\n" ) ;

    }
    while( more() );

Of course, you would have to have already defined these next items before you called them in main ...

#define MAX_NUM_DEPOSITS 5 /* can keep small for testing */

/* an array of const char pointers ... i.e. a 'ragged array' */
const char* NAMES[] = { "Sam", "Anna", "Joe", "Jane", "Bob" };


 /* handy utilities for many C student coding problems ... */
int takeInChr( const char* msg )
{
    char chr;
    printf( msg ); fflush( stdout );
    chr = getchar();
    if( chr != '\n' ) while( getchar() != '\n' ) ; /* flush stdin ... */
    return chr;
}
int more() /* defaults to 'true'/'yes'/'1' ... unless 'n' or 'N' entered */
{
    if( tolower( takeInChr( "More (y/n) ? " )) == 'n' ) return 0;
    /* else ... */
    return 1;
}

Hope this gives you some further insights to help you get past the common beginner coder ... 'looking a little lost' ... phase :)

commented: Appreciated... Now I got it! +0
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.