/* ----------------------------------------------------------------------- ** Figure 13.32 Gas pressures. ** Figure 13.33: Calculating gas pressure. ** ----------------------------------------------------------------------- */ #include "tools.h" #define R 8314 /* universal gas constant (N m / K mol) */ #define V 1.00 /* Use volume of 1 cubic meter */ void work( void ); void main( void ) { char do_more; banner(); puts("\n Gas Pressure Calculation"); do { work(); printf("\n Do you want more calculations (y/n)? "); scanf( " %c", &do_more ); } while ( tolower( do_more ) != 'n' ); bye(); } /* --------------------------------------------------------------------------- */ void work( void ) { int choice; /* for the gas menu selection */ float temp; /* temperature of gas, Kelvin */ float mass; /* mass in kilograms */ float moles; /* number of kmol of gas */ float pres; /* pressure, in KiloPascals, to be calculated */ /* ----- Table of gases -------------------------------------------------- */ #define N 5 /* number of gases in the menu */ string menu[N]= { "carbon dioxide", "carbon monoxide", "nitrogen", "oxygen", "steam"}; string formula[N]= { "C_O2", "C_O", "N2", "O2", "H2_O" }; float mwt[N]= { 44.011, 28.011, 28.013, 31.999, 18.015 }; /* ------------------------------------------------------------------------- */ choice = menu_i( " Please choose a gas:", N, menu ); printf( "\n Enter the temperature in degrees Kelvin: " ); scanf( "%g", &temp ); printf( " Enter the mass in kilograms: " ); scanf( "%g", &mass ); if (temp <= 0 || mass <= 0) { printf( " Inputs can't be negative, try again.\n" ); return; } moles = mass / mwt[choice]; /* kmol */ pres = (moles * R * temp) / (V * 1000) ; /* ideal gas equation, kPascals */ printf( "\n For %.2f kilograms of %s \n", mass, formula[choice] ); printf( " occupying %.2f cubic meters at %.2f degrees K, \n", V, temp ); printf( " pressure is %.3g kPa using ideal gas equation.\n", pres ); }