Finding mix & max of a calculated variable from an input file
I'm currently learning about fstream in my beginner C++ class. I have an assignment where I am asked to do various things. I have a file that I read the name of the cities and their affiliated cost of living including groceries, housing, etc. I use the cost of living to calculate the Index cost of the city for the whole input file I was given.
Code:
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
double computations(double&, double&, double&, double&, double&, double&);
int main()
{
string city;
double groceries, housing, utilities, transportation, health, misc, index;
ifstream inFile;
//open file; if fails exit program
inFile.open("C:\\Users\\Teddy Kim\\Downloads\\costIndex.txt");
if(inFile.fail())
{
cout << "File does not exist" << endl;
exit(100);
}
while (!inFile.eof())
{
getline(inFile, city);
inFile >> groceries >> housing >> utilities >> transportation >> health >> misc;
index = computations(groceries, housing, utilities, transportation, health, misc);
cout << index << endl;
string tempstr; getline(inFile, tempstr); system("pause");
}
}
double computations(double& g, double& h, double& u, double& t, double& he, double& m)
{
double total;
total = 0.13 * g + 0.29 * h + 0.10 * u + 0.12 * t + 0.12 * he + 0.24 * m;
return total;
}
Essentially, I have index set up as the calculation using the computations function for the cost of each city. The problem is now that I have to find the lowest and highest index value from the given set of data I just calculated. I have absolutely no clue on how to do that for a variable calculation based on an input file. I also have to be able to label the highest and lowest index with the affiliated string of city name. I won't show the whole input file because theres over a hundred lines but it looks like this and just repeats for different cities.
Quote:
Asheville, NC
104.6 97.8 113.1 94.2 104.7 100.6
I have not learned anything about arrays or vectors yet so I am not allowed to utilize those concepts. Can someone give me a hint or point me in the right direction on how to calculate the lowest & highest index as well as output the city name that is attached with the value?
Thank you!