Welcome to Dream.In.Code
Become a C++ Expert!

Join 137,271 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,440 people online right now. Registration is fast and FREE... Join Now!




Do-While Problem

 
Reply to this topicStart new topic

Do-While Problem

chadly724
6 Nov, 2006 - 07:08 PM
Post #1

New D.I.C Head
*

Joined: 26 Oct, 2006
Posts: 14


My Contributions
i need to write a function that starts with two values for friction. one is initialized to .02. then it solves for the new friction value. after that it compares the friction values. if
|fnew-fstart|<=.001 it stops and returns the fnew value. if not it plugs fnew into the equation and solves for fnew again... does this make sense. i can't figure it out.

take a look...

CODE

double Friction_Factor(double surf_roughness, double pipe_diameter, double reynolds_number)
{
    double friction_factor_old(0.2);
    double friction_factor_new;

    do
    {
    friction_factor_new=pow(-1/(((2*log10 (((surf_roughness/pipe_diameter)/3.7)+(2/(reynolds_number*sqrt (friction_factor_old)))))),2));

    friction_factor_old=friction_factor_new;
    }
    while (abs(friction_factor_new-friction_factor_old>.001));
    

    return friction_factor_new;

}

User is offlineProfile CardPM
+Quote Post

Videege
RE: Do-While Problem
6 Nov, 2006 - 10:23 PM
Post #2

rêvant.toujours
Group Icon

Joined: 25 Mar, 2003
Posts: 1,406


Dream Kudos: 150
My Contributions
your condition is inside the function call abs(), thus it will always evaluate true. it should be outside the function call to abs().
User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 12/4/08 07:53PM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month