#include <stdio.h>
#include <math.h>
#define PI 3.1416
void main(void)
{
int choice,tanknum,hosenum,hose,q;
float area,volume,height,radius,length,width,t...
float totaltime2=0;
printf("\nFinding volume of different shapes of tanks and ");
printf("\n~~~~~~~~~~~~~~~~~~~~~~~~~~~...
printf("\ntime taken to fill the tank with water\n");
printf("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~...
printf("\n\n How many tanks do you want to find? :");
scanf("%d",&tanknum);
for (q=1;q<=tanknum;q++)
{
printf("\n\nMenu of Choices\n");
printf("===============\n");
printf("1.Cylinder\n");
printf("2.Square tank\n");
printf("3.Rectangle tank\n");
printf("4.Quit\n\n");
printf(" Enter choice: ");
scanf("%d",&choice);
switch(choice)
{
case 1:printf("\nEnter the radius and height of the cylinder in metres:");
scanf("%f %f",&radius,&height);
area=PI*pow(radius,2);
volume=PI*pow(radius,2)*height;
printf("\nArea of cylinder is %.2f square metres.\n",area);
printf("Volume of cylinder is %.2f cubic metres.\n",volume);
printf("\nHow many hoses do you want to use(must be more than 1):");
scanf("%d",&hosenum);
printf("\nEnter the 1 Hose time taken(in minutes):");
scanf("%f",&time1);
totaltime1=1.0/time1;
for(hose=2;hose<=hosenum;hose++)
{
printf("Enter the %d Hose time taken(in minutes):",hose);
scanf("%f",&time2);
totaltime2=totaltime2+(1.0/time2)...
}//end for
break;
case 2: printf("\nEnter the length and height in metres:");
scanf("%f %f",&length,&height);
area=length*length;
volume=pow(length,2)*height;
printf("\nArea of square tank is %.2f square metres.\n",area);
printf("Volume of square tank is %.2f cubic metres.\n\n",volume);
printf("\nHow many hoses do you want to use(must be more than 1):");
scanf("%d",&hosenum);
printf("\nEnter the 1 Hose time taken(in minutes):");
scanf("%f",&time1);
totaltime1=1.0/time1;
for(hose=2;hose<=hosenum;hose++)
{
printf("Enter the %d Hose time taken(in minutes):",hose);
scanf("%f",&time2);
totaltime2=totaltime2+(1.0/time2)...
}//end for
break;
case 3:printf("\nEnter length, width and height of rectanglular tank in m:");
scanf("%f %f %f",&length,&width,&height);
area=length*width;
volume=length*width*height;
printf("\nArea of rectangular tank is %.2f square metres.\n",area);
printf("Volume of rectangular tank is %.2f cubic metres.\n\n",volume);
printf("\nHow many hoses do you want to use(must be more than 1):");
scanf("%d",&hosenum);
printf("\nEnter the 1 Hose time taken(in minutes):");
scanf("%f",&time1);
totaltime1=1.0/time1;
for(hose=2;hose<=hosenum;hose++)
{
printf("Enter the %d Hose time taken(in minutes):",hose);
scanf("%f",&time2);
totaltime2=totaltime2+(1.0/time2)...
}//end for
break;
case 4:printf("\nBye-bye\n");
break;
default:printf("\nInvalid choice!!\n");
}//end switch
if(time1<=0 || time2<=0)
{
printf("\nTime taken cannot be negative or 0.\n");
}//end if
else
{
total=1.0/(totaltime1+totaltime2)...
printf("\nTime taken to fill a tank is %.2f minutes.\n",total);
}//end else
}//end for
}//end main
Tags: