loops with data from a file

closed account (98qGz8AR)
i'm trying to figure out exactly how data is displayed from files. i've read all the pages on here about it but it's still not totally making sense. i have an assignment where a user enters a file destination, the program echoes the data, and then computes 4 different types of averages from the data.

i know i need to do some loops in there, but i don't know which kind would make the most sense, or how to code this. the teacher isn't much help at all. my code so far is:
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
#include <iostream>
#include <fstream>
#include <string>
#include <iomanip>
using namespace std;

const int COL_WID = 10;


int main()
{
	ifstream	in;
	ofstream	on;
	string		filePath;
	string		names;
	char		yesNo;
	int		age;
	double		score;

	cout << endl << "Please enter the file address: ";
	cin >> filePath;
	in.open(filePath.c_str());

	if(!in)
	{
		cerr << endl << filePath << " is not a valid directory."
			<< endl << endl;
		system("pause");
		exit(1);
	}

	in >> names;
	while(!in.eof())
	{
		in >> yesNo;
		in >> age;
		in >> score;

		//data processing
		cout << setw(COL_WID) << names << setw(COL_WID) << yesNo << setw(COL_WID) << age << setw(COL_WID) << score << endl;

		in >> names;



	}

	in.close();

	return 0;
}


as you can see i'm stuck after the data echo. can i use the istream variables ("in") to manipulate the data or the regular variable declared at the beginning of int main?

for reference, the data file it is echoing is set up like:
NAME Y/N AGE SCORE

and the loops for the averages i need to computer are something like
1
2
3
4
5
6
7
8
9
10
11
12
if(yesNo == 'Y'){
  if(age >= 18)
  //find average
  else if(age < 18)
  //find average
}
if(yesNo == 'N'){
  if(age >= 18)
  //find average
  else if(age < 18)
  //find average
}



any help or tips would be awesome.
thanks guys.
Topic archived. No new replies allowed.