Hi... I am new to the forums and new to C++. I have an assignment I have been working on and can't find where my error is in the program. I was just wondering if someone could take a glance at it and tell me why my calculations are incorrect. I realize this is easy stuff but I am a beginner. Here is the assignment description:

Engineers are designing a concrete channel which will bring water to the city reservoir from a near-by lake. The channel will have vertical walls and it will be 15 feet wide. It will have a roughness coefficient of 0.014. The water flow rate in the channel depends on the width, depth of the water, the roughness coefficient, and the slope of the channel. The relationship is given by Manning's equation:

Q = (1.486 / N) * A * R^2/3 * S^1/2

R = depth * width/ (2 * depth + width)

Q is the flow rate in cubic feet per second

R is the hydraulic radius

A is the area

S is the slope in feet/foot

N is the roughness coefficient

To help with the design of the channel, engineers want us to produce a table which shows the flow rate for each combination of slope 0.0014, 0.0015, 0.0016, 0.0017, and 0.0018 and depths 6, 8, 10, and 12 feet.

Write a C++ program that produces this table. Use nested loops to provide the slope and depth values. For example, the index variable on the outer loop can be a double variable with initial value of 0.0014. Input the width and roughness coefficient. The table should start out similar to the one below.

SLOPE DEPTH FLOW

________________________________________________

0.0014 6.0 797.5963

0.0014 8.0 1174.9401

0.0014 10.0 1571.7912

0.0015 6.0 825.5906

0.0015 8.0 1216.1786

0.0015 10.0 1626.9585

Okay... that is what I got from my instructor. Remember, this is very basic C++... we are only in the second chapter so the functions and operations are very basic.

Here is my code for this program:

I am using Microsoft Visual C++ to write my program, only because it came with the book.Code:`# include <iostream.h>`

# include <iomanip.h>

# include <math.h>

int main (void)

{

//Variable declaration

double Q; // flow rate

double R; // hydralic radius

double A; // area

double S; // slope

double N = 0.014; // roughness coefficient

double D; // depth

double W = 15; // width

//Output Headings

cout<<" SLOPE"<<setw(16)<<"DEPTH"<<setw(16)<<"FLOW"<<endl;

cout<<"__________________________________________"<<endl;

//Processing

for (S = 0.0014; S < 0.0019; S += 0.0001)

{

for (D = 6.0; D <= 12; D += 2)

{

A = D * W;

R = D * W / (2 * (D + W));

Q = (1.486 / N) * A * pow(R, 2/3) * pow(S, 0.5);

}

}

//Format Output

cout<<setw(10)<<setprecision(4)<<setiosflags(ios::fixed | ios::showpoint)<<S;

cout<<setw(16)<<setprecision(1)<<setiosflags(ios::fixed | ios::showpoint)<<D;

cout<<setw(16)<<setprecision(4)<<setiosflags(ios::fixed | ios::showpoint)<<Q<<endl;

}

return 0;

}

Here is the printout I get when I execute it:

SLOPE DEPTH FLOW

__________________________________________

0.0014 6.0 357.4352

0.0014 8.0 476.5802

0.0014 10.0 595.7253

0.0014 12.0 714.8704

0.0015 6.0 369.9806

0.0015 8.0 493.3074

0.0015 10.0 616.6343

0.0015 12.0 739.9611

0.0016 6.0 382.1143

0.0016 8.0 509.4857

0.0016 10.0 636.8571

0.0016 12.0 764.2286

0.0017 6.0 393.8744

0.0017 8.0 525.1659

0.0017 10.0 656.4573

0.0017 12.0 787.7488

0.0018 6.0 405.2934

0.0018 8.0 540.3912

0.0018 10.0 675.4890

0.0018 12.0 810.5868

Press any key to continue

Well, it looks kinda messed up because everything is crunched together, but I think you can tell what its supposed to be.

The numbers for the flow dont even come close to what I should be getting according to the example given on my handout. I am not asking anyone to write the program for me, only give any suggestions as to why my output is not correct. I am not sure if it is a problem with decimal's and rounding or what. I appreciate any help I can get :)

Thank you in advance for your time!

GrlNewB