Truly appreciate your patience and help
interpolate_ array should return 1.41..... Used to work- not now.
find_array_pos should return 3.
These are the times when I put it down and come back tomorrow
[CODE title="full code"]
#include <stdio.h>
#include <stdlib.h>*/
/***************************************************/
/*Prototype*/
double interpolate_array(double *boiler_abv, size_t array_len, double wash_abv);
int find_array_pos(double *boiler_abv, size_t array_len, double wash_abv);
double convert(const double *abv_to_abw, size_t abv_to_abw_len, double abv);
int main()
{
double boiler_abv[10] = { 0, 0.032, 0.062, 0.092, 0.12, 0.147, 0.174, 0.199, 0.224, 0.248 };
double boiler_abw[10] = { 0, 0.025, 0.05, 0.073, 0.096, 0.119, 0.14, 0.161, 0.182, 0.202 };
static const double abv_to_abw[9] = /*Array of E Croissants coefficients for conversion of alcohol by weight to alcohol by volume*/
{
0.00018684999875047631, 0.77602465132552556, 0.41803095099103116, -2.5221614925275091, 9.5827123045656251,
-19.928886159385002, 21.4165120890385651, -15.830262207383321, 4.3390473620304988
};
double wash_vol, wash_abv = 0;
printf("/nEnter ABV%% (0 to 1)");
scanf("%f", &wash_abv);
double interp_factor = 0;
interp_factor = interpolate_array(boiler_abv, sizeof(boiler_abv) / sizeof(boiler_abv[0]), wash_abv);
int array_pos = 0;
array_pos = find_array_pos(boiler_abv, sizeof(boiler_abv) / sizeof(boiler_abv[0]), wash_abv);
printf("\n pos = %d\n", array_pos);
printf("interp factor = %f\n", interp_factor);
system("PAUSE");
return (0);
}
/*****************************************************/
/*Definition*/
double interpolate_array(double boiler_abv[], size_t boiler_abv_len, double wash_abv)
{
int i;
for(size_t i = 0; i < boiler_abv_len; i++)
{
if(boiler_abv
== wash_abv)
{
double interp_factor = 1;
return interp_factor;
break;
}
else if (boiler_abv > wash_abv)
{
double low = boiler_abv[i-1];
double interp_factor = (wash_abv / low);
return interp_factor;
}
}
}
/********************************************************************************************************/
int find_array_pos(double boiler_abv[], size_t boiler_abv_len, double wash_abv)
{
for(size_t i = 0; i < boiler_abv_len; i++)
{
if(boiler_abv == wash_abv)
{
return i;
}
else if (boiler_abv > wash_abv)
{
return i-1;
}
}
}
/******************************************************************************************************/
double convert(const double abw_to_abv[], size_t abw_to_abv_len, double abw)
{
double abv = abw_to_abv[0];
double abw_mult = abw;
for (size_t i = 1; i < abw_to_abv_len; ++i)
{
abv = abv + abw_to_abv * abw_mult;
abw_mult *= abw;
}
return abv;
}[/CODE]