Advertisement
Guest User

Untitled

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