im working on a project on where i have to come up with Van der Waals equation and im having trouble with arrays....need help on how to call for the constants! i have no idea how to make it work correctly.....once, i have this correct, i would have to make a seperate func to calculate the equation.....but i want to work on the arrays first.
Code:#include <stdio.h>
#include <stdlib.h>
void elements(float*,float*);
void vd_constants(constants[6][2]);
int main()
{
FILE *output = NULL;
float p, /*Pressure*/
v, /*Volume of Container*/
T, /*Absolute Temperature*/
n, /*Input Number of Moles*/
user_element;
const float R=8.314472; /*Gas Constant*/
float *a, /*Inputted by user defined element*/
*b, /*Inputted by user defined element*/
eq1,
eq2,
eq;
if((output=fopen("c:answer.txt","w")) == NULL)
printf("Error opening data file.\n");
else
{
printf("Van der Waals Equation:\n\n");
printf(" an^2\n"
"(P + -----)(V-nb)=nRT\n"
" V^2\n\n");
elements(a,b);
printf("\n");
printf("a=%f b=%f\n\n",*a,*b);
printf("Please enter the amount of pressure, volume, and moles: "
"(separated by a space)\n\n");
scanf("%f %f %f",&p,&v,&n);
printf("\nPressure=%.3f Volume=%.3f Moles=%.3f\n\n",p,v,n);
eq1=p+(*a*(n*n/v*v));
eq2=v-(n**b);
eq=(eq1*eq2)/(n*R);
printf("Temperature is equal to %f Kelvin\n\n",eq);
fprintf(output,"Since a=%f and b=%f\n"
"Pressure=%f Volume=%f and Moles=%f\n\n"
"Temperature is equal to %f Kelvin\n\n",*a,*b,p,v,n,eq);
fclose(output);
}
system("PAUSE");
return 0;
}
void elements(float *a, float *b)
{
int user_element;
vd_constants(constants[6][2]);
printf("Which element do you want to solve for T?\n\n");
printf("1-Carbon Dioxide\n2-Helium\n3-Hydrogen chloride\n"
"4-Oxygen\n5-Sulfur dioxide\n6-Water\n\n");
scanf("%d",&user_element);
switch(user_element)
{
case 1:
*a=constants[1][1];
*b=constants[1][2];
break;
case 2:
*a=constants[2][1];
*b=constants[2][2];
break;
case 3:
*a=constants[3][1];
*b=constants[3][2];
break;
case 4:
*a=constants[4][1];
*b=constants[4][2];
break;
case 5:
*a=constants[5][1];
*b=constants[5][2];
break;
case 6:
*a=constants[6][1];
*b=constants[6][2];
break;
}
}
void vd_constants(constants[6][2])
{
constants[6][2]={{3.64, .04267},
{.03457, .0237},
{3.716, .04081},
{1.378, .03183},
{6.803, .05636},
{5.536, .03049}};
}

