Thread: can anyone solve this question for me i am having problems with it

  1. #1
    Registered User
    Join Date
    Dec 2020
    Posts
    2

    Post can anyone solve this question for me i am having problems with it

    The pressure of a gas changes as the volume and temperature of the gas vary. Write a program that uses the Van der Waals equation of state for gas,P * V = N * R * T You need to display in tabular form the relationship between the pressure and the volume of n moles gas at a constant temperature (T), P is the pressure and V is the volume. Use 8.3145 for gas constant R. Your program will output a table that variesthe volume of the gas from the initial to the final volume in steps prescribed by the volume increment. Your program should ask the user to continue or stop. To continue user must enter y, to stop n letter. If the user enters different letter from y or n the program should continue to ask again as in sample run. Assume that user can enter one letter.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    38,626
    Post your latest code.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Dec 2020
    Posts
    2

    Post

    Quote Originally Posted by Salem View Post
    Post your latest code.
    i got the calculation right but i cant input the name of gas because when i do the code wont work and i have a problem with asking the question (Do you want to continue (Y/n) should i write it inside the for loop or outside it.
    Code:
    #include<stdio.h>
    #define R 8.3145
    int main()
    
    
    {
        int    Temp;
        double  Gname, Vol, InitialVol, FinalVol, nmoles, Pressure, volIncremnet; 
        
        
        
        
            printf("Enter the name of a gas: \n");
             printf("quantity of %lf(moles): ");
             scanf(" %lf", &Gname);
             printf("Tempreture(Kelvin): ");
             scanf("%d", &Temp);
             printf("Initial Volume(Milliliters): ");
             scanf("%lf", &InitialVol);
             printf("Final Volume(Milliliters): ");
             scanf("%lf", &FinalVol);
             printf("Volume Increment(Milliliters): ");
             scanf("%lf", &volIncrement);
             
             printf("\n\n%.3lf moles of at %d Kelvin", Gname, Temp);
             
             printf("\nVolume (ml)    pressure (atm)"); 
           
           
        
        for(Vol=InitialVol;Vol<=FinalVol;Vol+=volIncrement)
         {
             
             
             printf("\n%2.0lf", Vol);
             
              Pressure=Gname*R*Temp/Vol;
              
             printf("            %9.4lf", Pressure);
        }
         
        
         
         
         return 0;
        
        
        
    }

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    38,626
    Where in your original description was there mention of the name of the gas?

    > printf("quantity of %lf(moles): ");
    > scanf(" %lf", &Gname);
    A name would be a string, say
    char Gname[20];

    Which you would use the %s format to both printf and scanf.


    > (Do you want to continue (Y/n) should i write it inside the for loop or outside it.
    Well the original description seems to suggest you produce a table, then ask.
    So outside seems appropriate.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 08-25-2020, 04:54 PM
  2. solve transportation problems by trapzoidal rule in c++
    By abualkhlil in forum C Programming
    Replies: 2
    Last Post: 05-05-2016, 07:35 AM
  3. Using C to Solve Problems
    By BB89 in forum C Programming
    Replies: 5
    Last Post: 09-30-2009, 12:25 PM
  4. No clue how to make a code to solve problems!
    By ctnzn in forum C Programming
    Replies: 8
    Last Post: 10-16-2008, 02:59 AM
  5. How Do You Solve Problems
    By manofsteel972 in forum A Brief History of Cprogramming.com
    Replies: 21
    Last Post: 12-04-2004, 10:25 AM

Tags for this Thread