• Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.

    To learn more about how to use our BBCode feature, please click here.

    Thank you, Code Forum.

Can't find my mistake


Active Coder
The calc_vle function takes an element of temperature array and calculates a value of x. The unique value x goes through an iteration until it's condition equation is satisfied. Then x is written to it's own arrray.
Everything about the function is executing correctly except writing the iterated and solved x1 to it's array.
x1 writes to screen print with correct and decrementing values.
But array values print to screen as zero.

What am I missing?


Screenshot (171).png

void calc_vle(int max_num, double atm_p, double pot_mol_0, double pot_mol_last, double *pot_mol, double *pot_temp,
               double (*calc_gamma_e)(double x1, double x2),
               double (*calc_gamma_w)(double x1, double x2),
               double (*calc_psat)(double A, double B, double C, double bp, double gamma, double x))
   double bp, x1, x2 = 0;
   double psat1 = 0;
   double psat2 = 0;
   double gamma_e = 0;
   double gamma_w = 0;

   pot_mol[max_num] = pot_mol_last;
   x1 = pot_mol_0;   //ethanol component of mixture in mols
   printf("VLE\tx1 = %lf", x1);
   x2 = 1-x1;

   for (int index = 0; index < max_num; index++)
    bp = pot_temp[index];

    gamma_e = calc_gamma_e(x1, x2);
    gamma_w = calc_gamma_w(x1, x2);

        psat1 = calc_psat(eA, eB, eC, bp, gamma_e, x1);  //Saturated vapor pressure ethanol
        psat2 = calc_psat(wA, wB, wC, bp, gamma_w, x2);  //Saturated vapor pressure water
        x1 -= 0.00001;
        printf("\nx1 = %lf", x1);
        printf("\npressure = %lf\ttemp = %lf\tnew x1 = %lf", psat1+psat2, pot_temp[index], pot_mol[index]);

    while (psat1 + psat2 > atm_p); //When sum of vapor pressures = or exceed atmospheric pressure the mixture is boiling
    pot_mol[index] = x1;