1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

How to convert floating point data type

Discussion in 'Meet and Greet' started by adityaismagic, Oct 2, 2012.

  1. adityaismagic

    adityaismagic New Member

    Joined:
    Oct 2, 2012
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    0
    HELP ME, PLEASE...
    i am developing software for some frnds of civil engg. dept. topic - Hydraulic Design for Sewage waste-water treatment, Grit Chamber Designing. I wrote program but it gives floating point overflow error.
    In code c_area variable goes to float overflow. how to convert data type of c_area (%2.4f) i.e. xx.xxxx.
    I tried to search on google for help but till no solution found
    code is _____________________________
    Code:
    include<stdio.h>
    #include<conio.h>
    #include<math.h>
    #include<limits.h>
    #include<float.h>
    
    int main()
    {
    	int op;
    	float maxflow, peakflow, set_velocity, s_gravity, p_diameter, temp;
    	float h_velocity, width, depth, length, d_time;
    	float c_area;
    
    	printf("\n Enter Maximum/Peak flow (in Mld) : "); //Mld=million liter per dad//
    	//let assume 20 Mld//
        scanf("%f",&maxflow);
        peakflow = (maxflow*pow(10,6))/(24*60*60*1000); //converting Mld into cu.m/sec//
        printf("\n                                  : %f cu.m/sec",peakflow);//it will be 0.2314 cu.m/sec//
    	printf("\n\n do you want to provide settling velocity");
    	printf("\n  1> yes\n  2> no");
    	printf("\n\n Enter your choise : ");
    	scanf("%d",&op);
    	switch(op)
    	{
    		case 1: printf("\n Enter Settling velocity (in m/sec) : ");//assume 0.02//
    		        scanf("%f",&set_velocity);
    		        break;
    		case 2: printf("\n Enter Specific velocity of particle : ");//assume 2.65//
    		        scanf("%f",&s_gravity);
    		        printf("\n Enter diameter of particle(in mm) : ");//assume 0.2//
    		        scanf("%f",&p_diameter);
    		        printf("\n Enter atmospheric temperature(in degree celcius) : ");//assume 20//
    		        scanf("%f",&temp);
    		        set_velocity = 60.6*(p_diameter/10)*(s_gravity-1)*((3*temp+70)/100);
    		        printf("\n Settling velocity is : %f cm/sec",set_velocity);//it will be 2.5997 cm/sec//
    		        printf("\n                      : %f m/sec",set_velocity/100);//it will be 0.02599 m/sec//
    		        break;
    	}
    	printf("\n\n Enter Horizontal velocity / Flow through velocity (in m/sec) : ");//assume 0.23 m/sec//
    	scanf("%2.4f",h_velocity);
    	c_area = peakflow/h_velocity;//overflow happens here, how to convert this value into %2.4f //
    	printf("\n Cross Sectional area : %f sq.m",c_area);
    	printf("\n\n Which of following parameter you can provide");
    	printf("\n  1>Width \n  2>Depth");
    	printf("\n Enter your choise : ");
    	scanf("%d",&op);
    	switch(op)
    	{
    		case 1: printf("\n Enter Width (in meter) : ");
    		        scanf("%f",&width);
    		        depth = c_area/width;
    		        printf("\n Depth : %f m",depth);
    		        break;
            case 2: printf("\n Enter Depth (in meter) : ");
                    scanf("%f",&depth);
                    width = c_area/depth;
                    printf("\n Width : %f m",width);
                    break;                
    	}
    	d_time = depth/set_velocity;
    	printf("\n\n Detention time : %f sec",d_time);
    	length = h_velocity * d_time;
    	printf("\n\n Length : %f m",length);
    	printf("\n Width  : %f m",width);
    	printf("\n Depth  : %f m",depth);
    	return(0);
    }
     
  2. hobbyist

    hobbyist New Member

    Joined:
    Jan 7, 2012
    Messages:
    141
    Likes Received:
    0
    Trophy Points:
    0
    have you tried a double?

    Code:
    scanf("%lf", &double_var);  // double
    or
    scanf("%Lf", &long_double_var); // long double
    
    printf("%2.4f", double_var);
    
     

Share This Page