I am in dire need of figuring out how to run this program using nested loops. It's a Van der Waal equation assignment, but I need to use nested loops for incremental increases. Here's what I have so far.
Code:
#include <iostream>
#include <iomanip>
#include <stdio.h>
using namespace std;
// Define constants.
#define a 3.952
#define b 0.0427
#define R 0.08206
#define mL_L .001
int main ()
{
float moles; //IN: Number of moles of CO2 (n).
float temp; //IN: Temperature (K).
float initial; //IN: Initial volume (mL).
float final; //IN: Final volume (mL).
float increment; //IN: Increment volume (mL) b/w lines of the table.
float pressure; //OUT: Pressure (atm).
float loopVol; //Variable assignment for loop function.
float volume; //Variable assignment for calculations.
//Request user input.
cout << "\nEnter the quantity of Carbon Dioxide (moles): ";
cin >> moles;
cout << "\nEnter the Temperature (K): ";
cin >> temp;
cout << "\nEnter the Initial Volume (mL): ";
cin >> initial;
cout << "\nEnter the Final Volume (mL): ";
cin >> final;
cout << "\nEnter the Volume Increment (mL): ";
cin >> increment;
//Set for table.
cout << "\n\nVolume (mL) Pressure (atm)" << endl;
//Begin calculations.
for(loopVol = initial; loopVol <= final; loopVol += increment)
{
printf(" %.2f", loopVol);
volume = loopVol * mL_L;
pressure = (moles * R * temp)/(volume - b * moles) - (a * moles * moles)/(volume * volume);
printf(" %.4f",pressure);
} while (loopVol <= final);
return 0;
}