Question

#include <iostream> #include <cmath> #include <iomanip> #include <cstdlib> using namespace std; bool isInt (double value) {...

#include <iostream>

#include <cmath>

#include <iomanip>

#include <cstdlib>

using namespace std;

bool isInt (double value) {

    double dummy;

    return bool(modf(value, &dummy) == 0);

}

double sqr(double value) {

return value * value;

}

double calcFrictionFactor(double R, double D, double epsilon)

{

    const double BlasiusCoefficient = 0.3164;

    double f_old, f_new;

    f_new = BlasiusCoefficient * pow(R, -0.25);

// loop until our two values are within 0.000001 of each other

    do {

  f_old = f_new; // previous guess is now the old one

  

      // plug guess into the right hand side of the ColeBrook formula

      f_new = 0.25 * pow(log10((epsilon/D)/3.7 + 2.51 / (R*sqrt(f_old))), -2);

    } while (fabs(f_new - f_old) > 0.000001);

    return f_new;

}

double calcReynolds (double rho, double V, double D, double mu ) {

double R;

R = (rho*V*D)/mu;

return R;

}

double calcPressureLoss(double V, double L, double D, double rho, double mu, double epsilon) {

double R;

double f;

double Delta;//pressure loss

R = calcReynolds (rho, V, D, mu);

if (R<3500){

return -1;

}else{

f = calcFrictionFactor (R, D, epsilon);

Delta = (f)*(L/D)*(rho)*((pow(V,2)/2));

return Delta;

}

}

void printTable(double V, double L, double rho, double mu, double epsilon){

double x;

int i;

double Delta;

double D;

Delta = calcPressureLoss(V, L, D, rho, mu, epsilon);

cout<<"Diameter (m)          Pressure Drop(Pa)"<<endl;

cout<<fixed<<showpoint;

for (i = 0; i<15; i++){

x = (i+1)*0.05;

cout<<setw(12)<<setprecision(2)<<x<<setw(12)<<setprecision(1)<<Delta<<setw(12)<<endl;             

}

}

int main (void) {

const double rho = 998.2;

double V;

double L;

double D;

const double mu = 1.002e-3;

const double epsilon = 0.045;

double R;

double Delta;

double x;

cout<<"Enter the value (-1 -1 to stop): ";

cin>>V>>L;

while (V!=-1&&L!=-1){

if (V<0||L<0){

cout<<"error"<<endl;

}else{

printTable(V, L, rho, mu, epsilon);

Delta = calcPressureLoss(V, L, D, rho, mu, epsilon);

}

cout<<"Enter the value (-1 -1 to stop): ";

    cin>>V>>L;

}//endwhile

    system("PAUSE"); return 0;

}

Need help.After compilation, the Pressure Drop should show the corresponding results, but Pressure Drop just keeps showing - 1. I try to debug it, and the program in highlight place cannot execute the content in else although the if conditions cannot be met.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

The variable D is passed as an argument without any initialization to the function calcPressureLoss from printTable function.

Hence a value like 6.91141e-310 is assigned to D and because of this, value like 1.37704e-303 is getting assigned to R which is less than 3500 for the first time when input values for V and L are entered.

Also in function main after calling printTable function, calcPressureLoss function is getting called with the variable D as an argument which is again not initialized. Hence in the function calcPressureLoss, value of D is assigned to 0. Hence value of R also becomes 0 for rest of the input values for V and L until -1 -1 is entered for them which meant to stop executing.

Thus if a proper value is initialized to D, this problem will be solved.

Add a comment
Know the answer?
Add Answer to:
#include <iostream> #include <cmath> #include <iomanip> #include <cstdlib> using namespace std; bool isInt (double value) {...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • #include <iostream> #include <vector> #include <iomanip> using namespace std; int main() { const int NUM_ITEMS =...

    #include <iostream> #include <vector> #include <iomanip> using namespace std; int main() { const int NUM_ITEMS = 8; vector <double> inverse(NUM_ITEMS); int j; double temp; for (int i = 0; i < NUM_ITEMS; i++) { inverse.at(i) = 1 / (i + 1.0); } cout << fixed << setprecision(2); cout << "Original vector..." << endl; for (int i = 0; i < NUM_ITEMS; i++) { cout << inverse.at(i) << " "; } cout << endl; cout << "Reversed vector..." << endl; for...

  • #include <iostream> #include <iomanip> #include <vector> #include <string> using namespace std; struct menuItemType { string menuItem;...

    #include <iostream> #include <iomanip> #include <vector> #include <string> using namespace std; struct menuItemType { string menuItem; double menuPrice; }; void getData(menuItemType menuList[]); void showMenu(menuItemType menuList[], int x); void printCheck(menuItemType menuList[], int menuOrder[], int x); int main() { const int menuItems = 8; menuItemType menuList[menuItems]; int menuOrder[menuItems] = {0}; int orderChoice = 0; bool ordering = true; int count = 0; getData(menuList); showMenu(menuList, menuItems); while(ordering) { cout << "Enter the number for the item you would\n" << "like to order, or...

  • This is C++ code for parking fee management program #include <iostream> #include <iomanip> using namespace std;...

    This is C++ code for parking fee management program #include <iostream> #include <iomanip> using namespace std; void input(char& car, int& ihour,int& imin, int& ohour, int& omin); void time(char car, int ihour, int imin, int ohour, int omin, int& phour, int& pmin, int& round, double& total); void parkingCharge (char car, int round, double& total); void print(char car, int ihour, int imin, int ohour, int omin, int phour, int pmin, int round, double total); int main() { char car; int ihour; int...

  • im not sure why my code isnt working? include <iostream> #include <iomanip> using namespace std; int...

    im not sure why my code isnt working? include <iostream> #include <iomanip> using namespace std; int main() { int amountOfCoffee; double Price; char salesTaxChargeability; double TotalAmount; const double SALESTAX = 0.035; // 3.5 % cout << "\nEnter the number of pounds of coffee ordered in Pounds :"; cin >> amountOfCoffee; cout << "\nEnter the price of coffee per Pound :"; cin >> Price; cout << "\nIs sales tax Chargeable (y or n): "; cin >> salesTaxChargeability; if ( (salesTaxChargeability ==...

  • #include<iostream> #include<string> #include<iomanip> using namespace std; /* ********* Class Car ************* ********************************* */ class Car {...

    #include<iostream> #include<string> #include<iomanip> using namespace std; /* ********* Class Car ************* ********************************* */ class Car { private: string reportingMark; int carNumber; string kind; bool loaded; string choice; string destination; public: Car() { reportingMark = ""; carNumber = 0; kind = "Others"; loaded = 0; destination = "NONE"; } ~Car() { } void setUpCar(string &reportingMark, int &carNumber, string &kind, bool &loaded, string &destination); }; void input(string &reportingMark, int &carNumber, string &kind, bool &loaded,string choice, string &destination); void output(string &reportingMark, int &carNumber,...

  • #include <iostream> #include <chrono> using namespace std; double improvedPow(double x, int y) { // To be...

    #include <iostream> #include <chrono> using namespace std; double improvedPow(double x, int y) { // To be implemented by you } int main() { cout << "To calculate x^y ..." << endl; double x; int y; cout << "Please enter x: "; cin >> x; cout << "Please enter y: "; cin >> y; if(x == 0) { if (y > 0) cout << 0 << endl; else cout << "x^y is not defined" <<endl; } else { cout << improvedPow(x,y)...

  • Flow chart of this program #include <iostream> #include <cmath> using namespace std; int mainO double sum=0.0,...

    Flow chart of this program #include <iostream> #include <cmath> using namespace std; int mainO double sum=0.0, ave-ee, int locmx, locmn int n; cout <<"Enter the number of students: "<<endl; cin >> ni double listln]; double max-0; double min-e; for (int i-e ; i<n ;i++) cout<s enter the gpa: "<cendli cin>>listli]; while (listlile i listli1>4) cout<s error,Try again "<cendl; cin>listlil: sun+=list[i]; N1 if (listli]>max) for(int isin itt) max=list [i]; 10cmx=1+1 ; else if (list [i] min) min=list [i]; locmn-i+1; ave sum/n;...

  • #include <iostream> #include <cmath> using namespace std; int main() { int x; int y; int z;...

    #include <iostream> #include <cmath> using namespace std; int main() { int x; int y; int z; int r1; int r2; cin >> x; cin >> y; cin >> z; r1 = 4* pow(x,3)-5*pow(y,2)+3*z; r2 = r1+7*pow(x,3)-2*pow(y,2)+11*z; cout << "r1="; cout << 4* pow(x,3)-5*pow(y,2)+3*z; cout << endl; cout << "r2="; cout << r1+7*pow(x,3)-2*pow(y,2)+11*z; cout << endl; cout << "r3="; cout << r2-9*pow(x,3)+22*pow(y,2)-6*z; cout << endl; return 0; } 1-115 Your output r2-395 13-186 5:Compare output Output differs. See highlights below. -163...

  • Use this code to create multiple functions. #include<iostream> #include<iomanip> #include<fstream> using namespace std; int main() {...

    Use this code to create multiple functions. #include<iostream> #include<iomanip> #include<fstream> using namespace std; int main() { cout << fixed << showpoint << setprecision(2); ofstream outFile; outFile.open("Feras's.txt"); outFile << "..Skinny Feras's Restaurant ..\n\n" << endl; int choise=10, quantity; float paid, SubTotal=0, Tax = .10, Total, RM, more; while(choise!=0) { system("cls"); cout << "\t**Welcome To Skinny Alsaif Restaurant Lol**" << endl; cout << "\nWhat would you like to have?" << endl; cout << "1. Burger." << endl; cout << "2. Pizza." <<...

  • Program 2 #include <iostream> #include <cmath> using namespace std; int main() {        const double PI...

    Program 2 #include <iostream> #include <cmath> using namespace std; int main() {        const double PI = 3.141592653;        int degrees;        double radians;        cout << "Enter a value for the degree of an angle\n";        cin >> degrees;        // translate the formula for converting degrees to radians into C++:        //            // degrees x PI        // ------------   = radians        //     180        radians = _____________________________________;        // Refer to p. 127 for help below....

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT