Please could any one know to to fix these mistakes

Please this C code for branched pipeline system

Page 1 of 1

2 Replies - 444 Views - Last Post: 28 October 2010 - 02:36 PM Rate Topic: -----

#1 kemoledo  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 28-October 10

Please could any one know to to fix these mistakes

Posted 28 October 2010 - 02:06 PM

i'm a 3rd year mechanical engineering and i never studied c and i make this c-code similar to the matlab one and it contains a lot of mistakes so any one could help me to fiix it here is the c-code:
   // Branched pipeline program
#include <iostream.h>
int main ()
{
// input data
	double g,t,ea,eb,ec,f1,f2,f3,l1,l2,l3,d1,d2,d3,r1,r2,r3,q1,q2,q3,q11,q22
	double q33,q
	g=9.8;
	t=.001;     // Tolerance value
	// head of tanks (m)
	ea=30;
    eb=27;
    ec=17;
    // length of pipes (m)
    l1=1000;
    l2=300;
    l3=600;
    // value of friction losses at each pipe
    f1=.03;
    f2=.03;
    f3=.04;
    // diameter of each pipe (m)
    d1=.3;
    d2=.2;
    d3=.2;
    // Calculation method
    // A- Get resistance in all pipes
    r1=(0.8*f1*l1)/(g*(d1)^5);
    r2=(0.8*f2*l2)/(g*(d2)^5);
    r3=(0.8*f3*l3)/(g*(d3)^5);
    for(ej=ec;ej<=ea;ej+.6)
    {
	q1=sqrt(((ea-ej)/r1));
    q2=sqrt(((ej-eb)/r2));
    q3=sqrt(((ej-ec)/r3));
        if (abs(q1-q2-q3)<=t); 
	cout << ej; 
	break
	else (ej=ea:ej>=ec:ej-.6:);
	cout << ej;
	cout << q;
	

    }
cout << "ej ==" <<ej << endl;
cout << "q1 ==" <<q1 << endl;
cout << "q2 ==" <<q2 << endl;
cout << "q3 ==" <<q3 << endl;
}   




and here the correct matlab source:

% this program is made to get the flow rate of 3 pipe networks connected to
% different tanks at different levels

clear
clc

%>>>>>>>>>>>>>>>>>> PROBLEM GIVEN DATA <<<<<<<<<<<<<<<<<<<<<<<<
g=9.8 ;
t=.001; % tolerance factor

% head of tanks (m)
ea=30;
eb=27;
ec=17;

% length of pipes (m)
l1=1000;
l2=300;
l3=600;

% value of friction losses at each pipe
f1=.03;
f2=.03;
f3=.04;

%diameter of each pipe (m)
d1=.3;
d2=.2;
d3=.2;

% ------------- /// Calculation Method \\\ -------------
% get resistance in all pipes
r1=(0.8*f1*l1)/(g*(d1)^5);
r2=(0.8*f2*l2)/(g*(d2)^5);
r3=(0.8*f3*l3)/(g*(d3)^5);

for ej=ec:.6:ea;
% get flow rate in each pipe
q1=sqrt(((ea-ej)/r1));
q2=sqrt(((ej-eb)/r2));
q3=sqrt(((ej-ec)/r3));

q=q1-q2-q3;
if abs(q)<=t; ej; break

else ej=ea:-.6:ec;
display(ej)
display(q)

end
end

% display all results

display(ej)
display(q1)
display(q2)
display(q3) 


so any one could help me

MOD EDIT: When posting code...USE CODE TAGS!!!

:code:

This post has been edited by JackOfAllTrades: 28 October 2010 - 02:08 PM


Is This A Good Question/Topic? 0
  • +

Replies To: Please could any one know to to fix these mistakes

#2 SarumanTheWhite  Icon User is offline

  • D.I.C Regular

Reputation: 73
  • View blog
  • Posts: 352
  • Joined: 04-November 08

Re: Please could any one know to to fix these mistakes

Posted 28 October 2010 - 02:19 PM

What're your error messages?
Was This Post Helpful? 0
  • +
  • -

#3 Beasty  Icon User is offline

  • New D.I.C Head
  • member icon

Reputation: 2
  • View blog
  • Posts: 20
  • Joined: 20-May 06

Re: Please could any one know to to fix these mistakes

Posted 28 October 2010 - 02:36 PM

There is no power operator in C.

You need to use the math lib.

http://www.cplusplus...rary/cmath/pow/

r1=(0.8*f1*l1)/(g*(d1)^5);  
r2=(0.8*f2*l2)/(g*(d2)^5);  
r3=(0.8*f3*l3)/(g*(d3)^5);  



There are also a few other errors in the code related to the math library. I'd suggest looking through the linked resource above for any function your using from mathlab.

This post has been edited by Beasty: 28 October 2010 - 02:38 PM

Was This Post Helpful? 2
  • +
  • -

Page 1 of 1