frain8

Untitled

Nov 19th, 2019
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.93 KB | None | 0 0
  1. /* Dasproc C - 2019
  2. William Handi Wijaya
  3. 0087
  4.  
  5. Memprediksi nilai kedalaman
  6. */
  7.  
  8. #include <stdio.h> //scanf and printf definition
  9. #include <math.h> // pow definition
  10. #define R_COEFF 0.014 //const of N
  11. #define SLOPE 0.0015 // slope of concrete
  12. #define FLOW 1000 //flow desired
  13. #define WIDTH 15 // width of concrete
  14. double cal_flow(double);
  15. int within_desired(double);
  16. int main()
  17. {  
  18.     double depth, // input - depth of concrete
  19.            temp_flow, //flow based on user's input of depth
  20.            difference, // output - difference of flow desired and user's flow
  21.            error; // output - error of guess
  22.     int flag = -1, // loop's sentinel
  23.         i = 0; //initiate begins of program
  24.     //intro program
  25.     printf("\nAt a depth of 5.0000 feet, the flow is 641.3255 cubic feet per second.");
  26.     //program loop
  27.     while(flag != 1)
  28.     {
  29.         if(i == 0) //begin of program
  30.         {
  31.             printf("\nEnter your initial guess for the channel depth when the flow is %d cubic feet per second", FLOW);
  32.             printf("\nEnter guess>");
  33.         }
  34.         else //if guess's flow still not in range
  35.             printf("\nEnter guess>");
  36.         //get the depth
  37.         scanf("%lf", &depth);
  38.         //calculate the flow
  39.         temp_flow = cal_flow(depth);
  40.        
  41.         difference = FLOW - temp_flow;
  42.         error = (difference / FLOW) * 100;
  43.         //printing the result
  44.         printf("\nDepth: %.3f Flow: %.3f cfs Target: 1000 cfs Difference: %.3f Error: %.3f percent", depth, temp_flow, difference, error);
  45.        
  46.         flag = within_desired(temp_flow);
  47.         i = -1;
  48.     }
  49. }
  50. //function to calculate the flow
  51. double cal_flow(double depth)
  52. {
  53.     double area, hydraulic_radius, temp_flow;
  54.    
  55.     hydraulic_radius = (depth * WIDTH) / ((2 * depth) + WIDTH);
  56.     area = depth * WIDTH;
  57.     temp_flow = (1.486/R_COEFF) * (area * pow(cbrt(hydraulic_radius), 2)) * sqrt(SLOPE);
  58.    
  59.     return temp_flow;
  60. }
  61. //function to verify the guess
  62. int within_desired(double num)
  63. {
  64.     if(num >= ((FLOW - ((0.1/100) * FLOW))) && (num <= (FLOW + ((0.1/100) * FLOW))))
  65.         return 1;
  66.     return 0;
  67. }
Advertisement
Add Comment
Please, Sign In to add comment