I have an incomplete program to solve different variations of the Bernoulli Equation. However with my if & else if statements It seems like it isn't computing the Boolean correctly or is skipping to the final else and executing that everytime.
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <cmath>
#include <string>
usingnamespace std;
//This program is to solve the Bernoulli equation
int main ()
{
double va, vb, pa, pb, j, g, h, eqnt, c, aa, ab;
cout<<"WELCOME TO BERNOULLIS DOME \n";
cout<<"Enter 1 for unknown value and 0 for unused value \n";
cout<<"Enter value for va-int. flowspeed (m/s)\n";
cin>>va;
cout<<"Enter value for vb-final flowspeed (m/s)\n";
cin>>vb;
cout<<"Enter value for pa-pressure(N/m^2)\n";
cin>>pa;
cout<<"Enter value for pb-pressure(N/m^2)\n";
cin>>pb;
cout<<"Enter value for j-density(kg/m^3)\n";
cin>>j;
cout<<"Enter value for h-height (m)\n";
cin>>h;
cout<<"Enter value for c-coefficient of friction\n";
cin>>c;
cout<<"Enter value for initial area\n";
cin>>aa;
cout<<"Enter value for final area\n";
cin>>ab;
g=9.18;
//cout<<"If Pressurized tank then type 1\n";
//cout<<"If Vented tank then type 2\n";
//cout<<"If Pressurized tank then type 3\n";
//cin>>eqnt;
//if (eqnt==1)
{
if (va == 1)
{
va=sqrt((2/(1-(aa*aa/ab*ab)))*(((pa-pb)/j)+g*h));
cout<<va<< "(m/s) \n";
}
elseif (vb == 1)
{
vb=sqrt((2/(1-(ab*ab/aa*aa)))*(((pb-pa)/j)+g*h));
cout<<vb<<"(m/s) \n";
}
elseif (pa == 1)
{
pa=j*g*h+pb+vb*vb*(1-(ab*ab/aa*aa));
cout<<pa<<"(N/m^2) \n";
}
elseif (pb == 1)
{
pb=j*g*h+pa-vb*vb*(1-(ab*ab/aa*aa));
cout<<pb<<"(N/m^2) \n";
}
else;
{
cout<<"you suck start over \n";
// NEED terminate command
}
}
/*else if (eqnt==2)
{
if (va==1)
{
vb=sqrt(2*(pa-pb)/j);
cout<<va<<"(m/s) \n";
}
else if (vb==1)
{
vb=sqrt(2*(pb-pa)/j);
cout<<vb<<"(m/s) \n";
}
}
*/
return 0;
}
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <cmath>
#include <string>
usingnamespace std;
//This program is to solve the bernoulli equation
int main ()
{
double va, vb, pa, pb, j, g, h, eqnt, c, aa, ab;
cout<<"WELCOME TO BERNOULLIS DOME \n";
cout<<"Enter 1 for unknown value and 0 for unused value \n";
cout<<"Enter value for va-int. flowspeed (m/s)\n";
cin>>va;
cout<<"Enter value for vb-final flowspeed (m/s)\n";
cin>>vb;
cout<<"Enter value for pa-pressure(N/m^2)\n";
cin>>pa;
cout<<"Enter value for pb-pressure(N/m^2)\n";
cin>>pb;
cout<<"Enter value for j-density(kg/m^3)\n";
cin>>j;
cout<<"Enter value for h-height (m)\n";
cin>>h;
cout<<"Enter value for c-coefficient of friction\n";
cin>>c;
cout<<"Enter value for initial area\n";
cin>>aa;
cout<<"Enter value for final area\n";
cin>>ab;
g=9.18;
//cout<<"If Pressurized tank then type 1\n";
//cout<<"If Vented tank then type 2\n";
//cout<<"If Pressurized tank then type 3\n";
//cin>>eqnt;
//if (eqnt==1)
{
if (va == 1)
{
va=sqrt((2/(1-(aa*aa/ab*ab)))*(((pa-pb)/j)+g*h));
cout<<va<< "(m/s) \n";
}
elseif (vb == 1)
{
vb=sqrt((2/(1-(ab*ab/aa*aa)))*(((pb-pa)/j)+g*h));
cout<<vb<<"(m/s) \n";
}
elseif (pa == 1)
{
pa=j*g*h+pb+vb*vb*(1-(ab*ab/aa*aa));
cout<<pa<<"(N/m^2) \n";
}
elseif (pb == 1)
{
pb=j*g*h+pa-vb*vb*(1-(ab*ab/aa*aa));
cout<<pb<<"(N/m^2) \n";
}
else
{
cout<<"you suck start over \n";
// NEED terminate command
}
}
/*else if (eqnt==2)
{
if (va==1)
{
vb=sqrt(2*(pa-pb)/j);
cout<<va<<"(m/s) \n";
}
else if (vb==1)
{
vb=sqrt(2*(pb-pa)/j);
cout<<vb<<"(m/s) \n";
}
}
*/
return 0;
}
1 // va ... this is the value I am looking for
10 //vb
.1 //pa
.2 // pb
1000 // j
10 // h
0 // c
100 // aa
10 //ab
with the output of
-1.#IND(m/s)
I am going to double check my equations... I don't know where else the error could come from
Edit*****
From trial and error I think my equation is off or the numbers im entering are off, I am going to redo my math by hand. ill post results shortly... thanks for your help