Hi, I am a newbie to C, and I am having issues while running the following code:
Code:
#include<stdio.h>
#include <math.h>
#include <stdlib.h>
#define rho_l 1000
int main()
{
float cw,eta,rho_m,rho_s,D_i;
float Re_b,tao_0,He,V;
float fnl,a,b,fnt;
float fn,m,fd,Pd_l;
char ch,ch1;
printf("\nIs the slurry density known?(Y/N) ");
scanf("%c",&ch);
if (ch == 'Y' || ch == 'y')
{
printf("\nEnter slurry density: ");
scanf("%f",&rho_m);
}
else //if (ch == 'N' || ch == 'n')
{
printf("\nIs solid density known?(Y/N) ");
scanf("%c",&ch1);
printf("%c is value of ch",ch1);
if (ch1 == 'Y' || ch1 == 'y')
{
printf("\nEnter solid density: ");
scanf("%f",&rho_s);
printf("\nInput Slurry Concentration: ");
scanf("%f",&cw);
rho_m = 100/((cw/rho_s)+((100-cw)/rho_l) ); //Calculate Slurry density
}
else if (ch1 == 'N' || ch1 == 'n')
{
printf("\nInsufficient data: ");
exit(0);
}
else
{
printf("\nInvalid Input!");
exit(0);
}
}
else
{
printf("\nInvalid Input!");
exit(0);
}
printf("\nInput Pipe Diameter: ");
scanf("%f",&D_i);
printf("Input flow velocity: ");
scanf("%f",&V);
printf("Input yield stress: ");
scanf("%f",&tao_0);
printf("Input Slurry Viscosity: ");
scanf("%f",&eta);
// Calculate Reynold's number for BinghamPlastic flow
Re_b = (D_i*V*rho_m)/eta;
printf("\n %f is the Reynold's number",Re_b);
// Calculate Hedstrom number
He = (pow(D_i,2.0)*rho_m*tao_0)/pow(eta,2.0);
printf("\n %f is the Hedstrom's number",He);
//Calculate friction factor in laminar regime
fnl = (16/Re_b)*(1 + Re_b/(6*He));
printf("\n %f is the laminar friction factor",fnl);
//Calcualte friction factor in turbulent regime
a = -1.47*(1+0.416*exp(-2.9*pow(10,-5)*He));
b = -0.193;
fnt = pow(10,a)*pow(Re_b,b);
printf("\n %f is the turbulent friction factor",fnt);
printf("\n %f is a",a);
//Calcualte overall Fanning friction factor
m = 1.7 + 40000/Re_b;
fn = pow((pow(fnl,m)+pow(fnt,m)),1/m);
printf("\n %f is m",m);
printf("\n %f is the overall friction factor",fn);
//Calcualte Darcy friction factor
fd = 4*fn;
printf("\n %f is the Darcy friction factor",fd);
//Calculate pressure drop per unit length
Pd_l = (rho_m*fd*pow(V,2.0))/(2*D_i);
printf("\n %f is the pressure drop in Pa/m",Pd_l );
return 0;
getch();
}
When I chose 'Y' for the first question
Code:
Is the slurry density known?(Y/N)
then the program works well, but when I chose 'N' then the program prints
Code:
Is solid density known?(Y/N)
and then. It does not take any input from me in that case.
The code does not go into the second if-else loop. How do I solve this problem?
Thanks...