Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Paul Jernigan, GROUP: none
- // Other group members: none
- // assign04a.c
- // September 22, 2017
- // This project was done alone with no outside assistance
- // This file adds onto project 3 by using a do-while loop to make sure the temperature input is within the required range.
- #include <stdio.h>
- #include <math.h>
- //*****CONSTANTS*****
- #define R 0.08314472 // the ideal-gas constant
- int main()
- {
- //*****INPUT*****
- // Get input variables as given in instructions
- double moles = 2, // mol
- volume = 1, // L
- a = 5.536, // L2atm/mol2
- b = 0.03049, // L/mol
- temp; // Fahrenheit
- // Print user input for temperature fahrenheit
- do {
- printf("Enter the gas temperature (1500 F - 2500 F): ");
- scanf("%lf", &temp);
- } while (temp < 1500 || temp > 2500);
- // Get a and b for gas #2
- printf("Enter a and b for the second gas: ");
- scanf("%lf %lf", &a, &b);
- double absTemp; // Kelvin
- // Output variables
- double pressureWaalsH20, // pressure for H20
- pressureWaalsGas2,
- pressureIdeal, // atmosphere
- pressDiff, // Difference between H20 and ideal
- pressDiff2, // Difference between gas 2 and ideal
- diff3, // Difference between gas 2 and h20
- diff4;
- // Other variables, if needed
- double p, // pressure
- nRT; // nRT
- //*****COMPUTE*****
- // Convert F temp to absolute temp K
- absTemp = fabs((( temp - 32) / 1.8) + 273.15);
- // Van der Waals pressure for H20:
- nRT = (moles * R) * absTemp;
- pressureWaalsH20 = ( nRT / (volume - moles * 0.0305)) - (5.46 * pow(moles, 2) / pow(volume, 2)) ;
- // Van der Waals pressure for gas #2:
- pressureWaalsGas2 = ( nRT / (volume - moles * b)) - (a * pow(moles, 2) / pow(volume, 2)) ;
- // Ideal pressure:
- pressureIdeal = (moles * R) * absTemp;
- // Difference for H20 and ideal pressure
- pressDiff = pressureWaalsH20 - pressureIdeal;
- // Difference for gas #2 and ideal pressure
- pressDiff2 = pressureWaalsGas2 - pressureIdeal;
- diff3 = pressDiff2 - pressDiff;
- diff4 = pressureIdeal - pressureWaalsH20;
- //*****OUTPUT*****
- // Blank line
- printf(" \n");
- // Display Waals pressure with label for H20
- printf("The Waals pressure (atm) for H20: %.2lf \n", pressureWaalsH20);
- // Display Waals pressure with label for gas #2:
- printf("The Waals pressure (atm) for gas #2: %.2lf \n", pressureWaalsGas2);
- // Display ideal pressure with label
- printf("The ideal pressure (atm) Ideal Gas Law: %.2lf \n", pressureIdeal);
- // Blank line 2
- printf(" \n");
- // Identify which gas pressure is greater and the difference, or that they're the same
- if (pressDiff2 > pressDiff) {
- printf("Gas#2 pressure is %.2lf atm higher than H20. \n", diff3);
- }
- else if (pressDiff2 < pressDiff) {
- printf("Gas#2 pressure is %.2lf atm lower than H20. \n", diff3);
- }
- else {
- printf("Gas#2 pressure is the same as H20. \n");
- }
- // Determine which Waals pressure is closer to Ideal pressure
- if (pressureWaalsH20 == pressureWaalsGas2) {
- printf("The Ideal Gas Law describes H20.");
- }else if (pressDiff2 < diff4) {
- printf("The Ideal Gas Law better describes Gas#2.");
- }
- else if (pressDiff2 > diff4) {
- printf("The Ideal Gas Law better describes H20.");
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement