#include <stdio.h>
#include <math.h>
int main(void)
{
double pd; // pressure drop in pounds per square inch (psi) / foot of pipe
double f; // flow in gallons per minute
double d; // inside pipe diameter (inches)
int c_factor; // factor (roughness or friction loss coefficient)
int type; // type of piping
int age; // age of cast-iron piping
printf ("Welcome To The Pressure Drop Calculator\n");
printf ("1. Cast Iron\n"); // C Factor Varies
printf ("2. Concrete\n"); // C Factor is 100
printf ("3. Copper\n"); // C Factor of 150
printf ("4. Steel \n"); // C Factor of 120
printf ("5. PVC (polyvinyl chloride\n"); // C Factor of 150
printf ("6. Other\n"); //C Factor Is Given By User
printf ("Please enter type of pipe according to numbers above:");
scanf ("%d", &type);
// switch to find out the type of pipe the user selected
switch (type)
{
case 1:
printf ("What is the age of the cast-iron pipe\n");
scanf ("%d", &age);
// If statement to find out C Factor related to the age of cast-iron pipe
if ( 0 <= age && age < 10 )
c_factor = 130;
if ( 10 <= age && age < 20 )
c_factor = 110;
if ( 20 <= age && age < 30 )
c_factor = 95;
if ( 30 <= age && age < 40 )
c_factor = 83;
else c_factor = 70;
break;
case 2:
c_factor = 100;
break;
case 3:
c_factor = 150;
break;
case 4:
c_factor = 120;
break;
case 5:
c_factor = 150;
break;
case 6:
printf ("Please enter the C factor of the pipe\n");
scanf ("%d", &c_factor);
while (c_factor <= 0)
{
printf ("Please enter a friction coefficient bigger than zero\n");
scanf ("%d", &c_factor);
printf ("\n");
}
break;
default : printf ("unknown pipe type %d\n", type);
}
printf ("The C Factor of the pipe is: %d", c_factor);
printf ("\n");
printf ("Please enter the diameter of the pipe:");
scanf ("%lf", &d);
printf ("\n");
// protection from dividing by zero and negative numbers
while (d <= 0)
printf ("Please enter a diameter greater than zero");
scanf ("%lf", &d);
printf ("\n");
printf ("To conclude, please enter the gallons per minute");
scanf ("%lf", &f);
printf ("\n\n");
// Calculation to find out pressure drop
pd = (4.52 * pow ( f, 1.85 ) ) / (pow ( c_factor, 1.85 ) * pow ( d, 4.87 ) );
printf ("The pressure drop is: %.4lf", pd);
printf ("\n\n");
return 0;
}