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

1. ## 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. Post your latest code.

3. Originally Posted by Salem
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. 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.

Popular pages Recent additions