Hello!
I am fairly new to programming. I am trying to finish this assignment from Hanley's C Program Design for Engineers. It is due on Monday, and I am trying to get it finished up this evening. I think there is either something wrong with my for loop or with the equation I am using.
When I compile and run my program, I am able to get it to print in a list the volume, but as for the pressure, it is printing out "nan".
What do I need to tweak?
Thanks for your help!Code:/**************************************************************************************** * Name: main * Returns: int; 0 for success * * Purpose: to compute Van der Waals equation of state for a gas. * Requires: stdio library function, printf, scanf, * Dependencies: none ****************************************************************************************/ /*includes*/ #include <stdio.h> #include <math.h> /*define contstants for Van der Waals' equation*/ #define R 0.08206 #define A 3.592 #define B 0.0427 /******************************************************************* * This is the main function ********************************************************************/ void instruct(void); int main(void) { double n_moles; /*the number of moles the user inputs*/ double int_volume; /*the initial volume as input by the user*/ double kelvin_temp; /*the temperature in Kelvins as input by user*/ double increment_vol; /*the increment volume given by the user*/ double final_vol; /*the final volume given by the user*/ double pressure; /*the pressure*/ double volume; /*volume*/ instruct (); printf("\n\n\nPlease input the quanity of carbon dioxide (moles)>>"); scanf( "%lf", &n_moles); printf("\n\nTemperature (Kelvins)>>"); scanf( "%lf", &kelvin_temp); printf("\n\nInitial volume (milliliters)>>"); scanf("%lf", &int_volume); printf("\n\nFinal volume (milliliters)>>"); scanf("%lf", &final_vol); printf("\n\nVolume increment (milliliters)>>"); scanf("%lf", &increment_vol); printf("Volume (ml) Pressure (atm)"); /*P =( nRT/(Vnb))-n^2a/V^2*/ pressure = ( n_moles*R*kelvin_temp/(volume*n_moles*B))-n_moles*n_moles*A/volume*volume ; { for (volume =int_volume; volume <= final_vol; volume +=increment_vol) printf("\n\n%5.4lf %5.4lf\n",volume, pressure); } return 0; } // end function main () ************************************** /******************************************************************* * This is the instruct function--it gives instructions to the user *******************************************************************/ void instruct (void) { printf("\n\n\nPlease enter at the prompts "); printf("the number of moles of carbon dioxide "); printf("the absolute\n temperature, the initial volume in millimeters "); printf("the final volume, \nand the increment volume between lines of the table\n\n"); }
Sarah