hi,
can someone pls help? thx!
i'm supposed to program this: user guesses the depth of water in a channel. the program will calculate the flow rate (Q). if Q is between 999 and 1001, the depth is deemed a correct guess. else will keep guessing till it falls within the range.
the answer is ideally 6.92. however, input of 7, 8, 9, 10 all states that the guess is too low.
Code:
#include <stdio.h>
#include <math.h>
double depth, width = 15, Q, N = 0.014, A, R, S = 0.0015;
/*double hydraulic_radius_eqn(double R)
{
R = (depth*width)/(2.0*depth + width);
return R;
}*/
double flow_eqn(double Q)
{
Q = 1.486*A*pow((depth*width)/(2.0*depth + width),2/3)*pow(S,1/2)/N;
return Q;
}
main(void)
{
printf("This program informs the user if the guessed depth of water us too high or low.\n");
printf("The channel of water has vertical walls 15 feet wide, 10 feet deep.\n");
printf("The slope is 0.0015 feet/foot, roughness coefficient of 0.014.\n");
printf("The flow rate is 1000 cubic feet per second.\n");
printf("You are to guess the depth of water until you are within 0.1 percent of the desired flow.\n\n");
printf("Guess the depth of water in the channel: ");
scanf("%lf", &depth);
Q = flow_eqn(depth);
while (Q>1001 || Q<999){
if (depth<=10){
if(Q>1001){
printf("Your guess is too high. Please guess a smaller depth.\nDepth: ");
scanf("%lf", &depth);
Q = flow_eqn(depth);
}
else{
printf("Your guess is too low. Please guess a larger depth.\nDepth: ");
scanf("%lf", &depth);
Q = flow_eqn(depth);
}
}
else {
printf("The channel is 10 feet tall. Please guess a water depth lesser than 10 feet.\nDepth: ");
scanf("%lf", &depth);
}
}
printf("You guessed it! The water depth is %lf feet!", &depth);
}