3 equations but C++ code is not executing

Hi there

I've had some great responses on this website for other queries.
I've written the code below but I can't understand why it is not executing.
The objective is to write the following steps:

Step 1: Find CF
CF = 0.91+(0.21*(h1/L))+(0.24*(h1/(h1+Ps))-0.35)

Step 2: Find Cd
Cd = 0.848*CF

Step 3: Find flow
flow = Cd*1.705*b*pow(h1,1.5)

Are there any obvious ways of fixing the C++ coding below?

#include <iostream>
#include <math.h> /* pow */
using namespace std;

int main( )
{
float Cd, CF, b, h1, L, Ps, flow;
cout << "Enter b in metres: ";
cin >> b;
cout << "Enter h1 in metres: ";
cin >> h1;
cout << "Enter L in metres. ";
cin >> L;
cout << "Enter Ps in metres. ";
cin >> Ps;
CF = 0.91+(0.21*(h1/L))+(0.24*(h1/(h1+Ps))-0.35);
cout << CF << endl;
Cd = 0.848*CF;
cout << Cd << endl;
flow = Cd*1.705*b*pow(h1,1.5);
cout << "Q = " << flow << endl;
return 0;
}

Thanks in advance!

James Cox
This executes fine in MCVS 2013. What errors are you experiencing?
Give the actual error message, if any.

If the console is abruptly closing as soon as you give your input, see http://www.cplusplus.com/forum/beginner/1988/
A good IDE should let you keep the console window open after execution automatically, otherwise follow the suggestions Duoas gave in that thread.

You can always test your code online at ideone.com or cpp.sh
Last edited on
If the console is not staying open try running your application with the following hot keys: [CTRL+F5]
closed account (48T7M4Gy)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include <iostream>
#include <math.h> /* pow */
using namespace std;

int main( )
{
   float Cd, CF, b, h1, L, Ps, flow;

   cout << "Enter b in metres: ";
   cin >> b;

   cout << "Enter h1 in metres: ";
   cin >> h1;

   cout << "Enter L in metres. ";
   cin >> L;

   cout << "Enter Ps in metres. ";
   cin >> Ps;

   CF = 0.91+(0.21*(h1/L))+(0.24*(h1/(h1+Ps))-0.35);
   cout << CF << endl;

   Cd = 0.848*CF;
   cout << Cd << endl;

   flow = Cd*1.705*b*pow(h1,1.5);
   cout << "Q = " << flow << endl;

   return 0;
}


Please indent your code properly and put code tags around it using the toolbox <> on the right. We can run it using the gear wheel when you do that in future posts. :)

Running it this way gives the following output:
Enter b in metres: 2
Enter h1 in metres: 3
Enter L in metres. 5
Enter Ps in metres. 2
0.83
0.70384
Q = 12.4713
 
Exit code: 0 (normal program termination)


What's wrong with that? :]
Last edited on
Wow 4 replies.

Thanks for all the thorough responses.

Mr Impact, I will take a look at MCVS 2013.

Ganado, I took a look at the website http://cpp.sh/ and enter the code into the C++ Shell.
As you mentioned the code runs in the shell. so the code is okay.

Thanks kemort, I'll tidy up my C++ code in the future.
Topic archived. No new replies allowed.