Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Program untuk memprediksi nilai kedalaman
- /* Programmer : William Handi Wijaya Tanggal diselesaikan : 22 November 2019
- NRP : 05111940000087 Kelas : Dasar Pemograman C */
- #include <stdio.h> //scanf and printf definition
- #include <math.h> // pow definition
- #define R_COEFF 0.014 //const of N
- #define SLOPE 0.0015 // slope of concrete
- #define FLOW 1000 //flow desired
- #define WIDTH 15 // width of concrete
- double cal_flow(double);
- int within_desired(double);
- int main(void)
- {
- double depth, // input - depth of concrete
- temp_flow, //flow based on user's input of depth
- difference, // output - difference of flow desired and user's flow
- error; // output - error of guess
- int flag = -1, // loop's sentinel
- i = 0; //initiate begins of program
- //intro program
- printf("\nAt a depth of 5.0000 feet, the flow is 641.3255 cubic feet per second.");
- //program loop
- while(flag != 1)
- {
- if(i == 0) //begin of program
- {
- printf("\nEnter your initial guess for the channel depth when the flow is %d cubic feet per second", FLOW);
- printf("\nEnter guess>");
- }
- else //if guess's flow still not in range
- printf("\nEnter guess>");
- //get the depth
- scanf("%lf", &depth);
- //calculate the flow
- temp_flow = cal_flow(depth);
- difference = FLOW - temp_flow;
- error = (difference / FLOW) * 100;
- //printing the result
- printf("\nDepth: %.3f Flow: %.3f cfs Target: 1000 cfs Difference: %.3f Error: %.3f percent", depth, temp_flow, difference, error);
- flag = within_desired(temp_flow);
- i = -1;
- }
- }
- //function to calculate the flow
- double cal_flow(double depth)
- {
- double area, hydraulic_radius, temp_flow;
- hydraulic_radius = (depth * WIDTH) / ((2 * depth) + WIDTH);
- area = depth * WIDTH;
- temp_flow = (1.486/R_COEFF) * (area * pow(cbrt(hydraulic_radius), 2)) * sqrt(SLOPE);
- return temp_flow;
- }
- //function to verify the guess
- int within_desired(double num)
- {
- if(num >= ((FLOW - ((0.1/100) * FLOW))) && (num <= (FLOW + ((0.1/100) * FLOW))))
- return 1;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement