#include <stdio.h>
#include <math.h>
#include <string.h>

typedef struct
{

    double rough;
    double slope;
    double width;
    double depth;
    char name[9];

}CHANNEL;

int display(CHANNEL*);
double calculatevelocity(CHANNEL);

void main()
{
    int index;
    double velocity;
    CHANNEL channel[4] =
        {
            {0.035,0.0001,10,2,"Channel 1"},
            {0.020,0.0002,8,1,"Channel 2"},
            {0.015,0.0010,20,1.5,"Channel 3"},
            {0.030,0.0007,24,3,"Channel 4"}

        };

    index=display(&channel);


    velocity=calculatevelocity(channel[index]);

    printf("\nFor %s, the average velocity is %.4f m/s",channel[index].name,velocity);

}
int display (CHANNEL *C)
{
    int answer;

    printf("Select the channel for which you want to calculate the velocity by entering 1, 2, 3 or 4: ");



    printf("\nChannel of Choice: ");
    scanf("%d",&answer);
    answer=answer-1;
    return(answer);


}

double calculateVelocity(CHANNEL channel)
{
    double velocity;

    velocity = pow(((channel.width/channel.depth)/(channel.width + (2 * channel.depth))), 2.0/3.0);
    velocity = velocity * (sqrt(channel.slope)/channel.rough);
    return velocity;
}
