1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
|
#include <iostream>
#include <iomanip>
#include <cmath>
#include <fstream>
#include <cstdlib>
#include <string>
using namespace std;
double indexCalc(string, double, double, double, double, double, double);
int main()
{
string line, lowest, highest;
double groceries, housing, utilities, transportation, health, miscellaneous, index, high, low;
ifstream inFile;
ofstream outFile;
int count = 0;
inFile.open("costIndex.txt");
if (inFile.fail())
{ cout << "No such file";
system("pause");
exit(100);
}
while (!inFile.eof())
{
getline (inFile, line);
cout << line << endl;
inFile >> groceries;
cout << groceries << endl;
inFile >> housing;
cout << housing << endl;
inFile >> utilities;
cout << utilities << endl;
inFile >> transportation;
cout << transportation << endl;
inFile >> health;
cout << health << endl;
inFile >> miscellaneous;
cout << miscellaneous << endl;
index = indexCalc(line, groceries, housing, utilities, transportation, health, miscellaneous);
inFile.close();
cout << setprecision(1) << fixed << index;
outFile.open ("index.txt");
outFile << line << endl;
outFile << groceries << endl;
outFile << housing << endl;
outFile << utilities << endl;
outFile << transportation << endl;
outFile << health << endl;
outFile << miscellaneous << endl;
outFile << setprecision(1) << fixed << index << endl;
outFile.close();
count++;
}
}
double indexCalc(string line, double groceries, double housing, double utilities, double transportation, double health, double miscellaneous)
{
double ind;
ind = (groceries * 0.13) + (housing * 0.29) + (utilities * 0.10) + (transportation * 0.12) + (health * 0.12) + (miscellaneous * 0.24);
return ind;
}
|