Van der Waals Equation

I have created a program, but I can not get it to match the sample run provided. Any suggestions? I really just need someone to look over, it could be something simple.

Here is what sample inputs are just going down list

.02
300
400
600
50

0.0200 moles of carbon dioxide at 300 kelvin

volume (ml) pressure (atm)
400 1.2246
450 1.0891
500 0.9807
550 0.8918
600 0.8178

If you run my program, you see that isn't the values I'm getting. I'm pretty sure of my equation, maybe I've just typed it wrong?

Thanks for any help!
Here is program!

//Setup standard environment
#include <iostream>
#include <cmath>
#include <iomanip>


using namespace std;

void title ()
{
// Output program name
cout << endl;
cout<< " Assignment 4 " <<endl;
}

int main ()

{
//Variable declarations
const double constant_a= 3.592, constant_b= 0.0427, constant_r=0.08206;
double v, n, t, initialv, finalv, increment, pressure; //Defined all used variable
char sentinel; //sentinel=n continue
//sentinel=y done

// Display title
title ();

cout <<endl <<endl;

cout << "Please enter at the prompts the number of moles of carbon \ndioxide, the absolute temperature, the initial volume in \nmilliliters, the final volume, and the increment volume \nbetween lines of the table. \n\n";

cout << "Please enter quantity of carbon dioxide (moles): ";

cin >> n;

cout << "\nPlease enter the temperature (kelvin): ";

cin >> t;

cout << "\nPlease enter initial volume (milliliters): ";

cin >> initialv;

cout << "\nPlease enter the final volume (mililiters): ";

cin >> finalv;

cout << "\nPlease enter the volume increment (mililiters): ";

cin >> increment;

cout << endl << n <<" moles of carbon dioxide at " << t <<" kelvin. \n \n";

cout << " Volume (ml) Presure (atm)\n\n";

for (v = initialv; v <= finalv; v +=increment)
{
(pressure= ((n*constant_r*t)/(v-(constant_b*n)))-((constant_a*n*n)/(v*v)));

cout << setw(7) << v << setw(20) << pressure <<endl;
}


cout << endl << "Assignment 4 is complete. \n\n";


return 0;
}
umm, It's been a while since I took chemistry, remind me the van der wall's equation?
Instead of typing it and it look confusing, http://en.wikipedia.org/wiki/Van_Der_Waals_Equation

The second one is the one they gave me to adapt to use for the program. It has been a while since I took Chemistry too...that may be my problem haha.
Yea I wrote a c++ all in one chemistry calculator my junior year...I'll see if I still have the source, and see if I can figure out something that will help. It's probably in the equation you used. I can't think of anywhere else your code would fall through.
Thanks, that'd be great. I'm working on it too, but so far I'm not getting anywheres.
If I multiple the formula by 1000 the answers are very familiar.... may help solve the problem?
that would imply your units are wrong. either for volume or mass :O
yay! that made so much sense. That's fixed. So one last question, how can I cut it off from adding e-.05706 or whatever. I just want it to stop after 6 places, i.e. 1.2246
set precision and turn scientific notian off...

setprecesion() scientific
Last edited on
Where exactly do I put that, I've never did that?
help please!
Topic archived. No new replies allowed.