Getting multiple lines and numbers from a text file without using arrays..?

This program is supposed to pull names of cities from a text file, followed by six numbers for each city. Then it is supposed to do a calculation with those six numbers and output the highest and lowest calculation to cout and to another file. I am able to get the first city name and its numbers, but when the loop repeats it just gives me the same string and numbers. Not only that, but it stops after the second loop for some reason and doesn't show the city name again. So could anyone help me understand how to be able to pull out a large amount of strings and numbers from a text file for further calculation and comparison? Any help appreciated.

Here's a copy of what the program outputs:

Anniston-Calhoun, County, ALt
101.2
74.8
111.2
88.8
89.3
96.6
90.5
101.2 <------ starts repeating first values here instead of moving to next town.
74.8
111.2
88.8
89.3
96.6
90.5
Process returned 0 (0x0) execution time : 0.141 s
Press any key to continue.



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;
}
Topic archived. No new replies allowed.