Advertisement
Guest User

assign04a-comp1200

a guest
Sep 20th, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.54 KB | None | 0 0
  1. // Paul Jernigan, GROUP: none
  2. // Other group members: none
  3. // assign04a.c
  4. // September 22, 2017
  5. // This project was done alone with no outside assistance
  6. // This file adds onto project 3 by using a do-while loop to make sure the temperature input is within the required range.  
  7. #include <stdio.h>
  8. #include <math.h>
  9. //*****CONSTANTS*****
  10. #define R 0.08314472    // the ideal-gas constant
  11.  
  12. int main()
  13. {
  14.  
  15.    //*****INPUT*****
  16.    // Get input variables as given in instructions
  17.    double moles  = 2,         // mol
  18.           volume = 1,         // L
  19.           a      = 5.536,     // L2atm/mol2
  20.           b      = 0.03049,   // L/mol
  21.           temp;               // Fahrenheit
  22.    // Print user input for temperature fahrenheit
  23.    do {
  24.    printf("Enter the gas temperature (1500 F - 2500 F): ");
  25.    scanf("%lf", &temp);
  26.    } while (temp < 1500 || temp > 2500);
  27.    
  28.    
  29.    // Get a and b for gas #2
  30.    printf("Enter a and b for the second gas: ");
  31.    scanf("%lf %lf", &a, &b);
  32.    double absTemp;            // Kelvin
  33.    // Output variables
  34.    double pressureWaalsH20,      // pressure for H20
  35.           pressureWaalsGas2,
  36.           pressureIdeal,      // atmosphere
  37.           pressDiff,          // Difference between H20 and ideal
  38.           pressDiff2,         // Difference between gas 2 and ideal
  39.           diff3,              // Difference between gas 2 and h20
  40.           diff4;
  41.    // Other variables, if needed
  42.    double p,                  // pressure
  43.           nRT;                // nRT
  44.          
  45.          
  46.    //*****COMPUTE*****
  47.    // Convert F temp to absolute temp K
  48.    absTemp = fabs((( temp - 32) / 1.8) + 273.15);
  49.    // Van der Waals pressure for H20:
  50.    nRT = (moles * R) * absTemp;
  51.    pressureWaalsH20 = ( nRT / (volume - moles * 0.0305)) - (5.46 * pow(moles, 2) / pow(volume, 2)) ;
  52.    // Van der Waals pressure for gas #2:
  53.    pressureWaalsGas2 = ( nRT / (volume - moles * b)) - (a * pow(moles, 2) / pow(volume, 2)) ;
  54.    // Ideal pressure:
  55.    pressureIdeal = (moles * R) * absTemp;
  56.    // Difference for H20 and ideal pressure
  57.    pressDiff = pressureWaalsH20 - pressureIdeal;
  58.    // Difference for gas #2 and ideal pressure
  59.    pressDiff2 = pressureWaalsGas2 - pressureIdeal;
  60.    diff3 = pressDiff2 - pressDiff;
  61.    diff4 = pressureIdeal - pressureWaalsH20;
  62.    
  63.    //*****OUTPUT*****  
  64.    // Blank line
  65.    printf(" \n");
  66.    // Display Waals pressure with label for H20
  67.    printf("The Waals pressure (atm) for H20: %.2lf \n", pressureWaalsH20);
  68.    // Display Waals pressure with label for gas #2:
  69.    printf("The Waals pressure (atm) for gas #2: %.2lf \n", pressureWaalsGas2);
  70.    // Display ideal pressure with label
  71.    printf("The ideal pressure (atm) Ideal Gas Law: %.2lf \n", pressureIdeal);  
  72.    // Blank line 2
  73.    printf(" \n");
  74.    // Identify which gas pressure is greater and the difference, or that they're the same
  75.    if (pressDiff2 > pressDiff) {
  76.       printf("Gas#2 pressure is %.2lf atm higher than H20. \n", diff3);
  77.    }
  78.    else if (pressDiff2 < pressDiff) {
  79.       printf("Gas#2 pressure is %.2lf atm lower than H20. \n", diff3);
  80.    }
  81.    else {
  82.       printf("Gas#2 pressure is the same as H20. \n");
  83.    }
  84.    // Determine which Waals pressure is closer to Ideal pressure
  85.    if (pressureWaalsH20 == pressureWaalsGas2) {
  86.     printf("The Ideal Gas Law describes H20.");
  87.    }else if (pressDiff2 < diff4) {
  88.       printf("The Ideal Gas Law better describes Gas#2.");
  89.    }
  90.    else if (pressDiff2 > diff4) {
  91.       printf("The Ideal Gas Law better describes H20.");
  92.    }
  93.      
  94.          
  95.    return 0;
  96. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement