I have an input file that consists of data in the form "Celsius,Resistance", for example one point is "5,12700" which stands for a temperature of 5 degrees Celsius, my resistance is 12700. This input file consists of multiple sets of data each on their individual line.
Here's a small part of the data:
I am trying to enter a resistance value of my choice, and return a temperature that corresponds to the resistance I entered. However, the resistance I input might not be an exact data set in the input file so I'm trying to linearly interpolate to assure accurate results where my inputted resistance value falls between two data points.
I'm unsure on how to get the two data points which fall both above and below my inputted resistance so I can linearly interpolate both sets of data as well as my inputted resistance to return the corresponding degrees Celsius. My linear interpolation formula I'm using is
Celsius = resis1 + (resistance - temp1) * ((resis2 - resis1) / (temp2 - temp1))
with temp1,resis1 being the data point below and temp2,resis2 being the data point above my inputted resistance.
Anything helps! Thanks for taking the time to help!
Here is a rough start to what I have.
using namespace std;
int resistance, celsius, temp1, temp2, resis1, resis2;
cout << "Problem opening input file";
cout << "Enter your resistance (enter -1 to quit): ";
cin >> resistance;
// Here is where I am stuck. I am unsure on how to search through my input file to obtain the boundary points that are above and below my inputted resistance
celsius = resis1 + (resistance - temp1) * ((resis2 - resis1) / (temp2 - temp1));
cout << "For a resistance of " << resistance << " the corresponding temperature is ";
cout << celsius << " degrees Celcius.";
} while (resistance != -1);
Also, here is the project I am attempting to complete.
I will provide you with 6 resistance values and you will calculate the corresponding temperature values (in Celsius). You will need to linearly interpolate, as needed, to assure accurate results where the given resistance
may fall between two data points.
You are to reject any resistance values that are
less than/greater than the high and low values in the data table.
Your task is to read in the thermistor data (unknown number of data points . . .) and prompt for the 5 test resistance values that I provide. For each resistance value you will produce a temperature