Having problems reading in from/writing to files in C++

I am writing a program that reads in a list of pilots' names followed by a set of coordinates for each pilot from a file. The program takes the pilots' coordinates, converts it to an area, and then writes the pilots' names and areas to a separate file. The number of pilots in the input file can be unlimited so the program needs to keep running until all the pilots and coordinates converted to areas have been written to the output file. Right now the program only writes one line to the output file. What am I doing wrong?

Here is what the input file looks like:

Jim 4,10 9,7 11,2 2,2 4,10
Sam 2,2 2,-2 -2,-2 -2,2 2,2
Marco 5,5 5,-5 -5,-5 -5,5 5,5
Polo 7,3 6,-9 -1,-2 -4,4 7,3

This is all I am getting for the output:

Jim 45.50

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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#include <fstream>
#include <string>
#include <iomanip>
#include <stdlib.h>
using namespace std;

void read(static ifstream &, string &, float[], float[]);
float calculate(float[], float[]);
void write(static ofstream &, string, float);

int main()
{
	ifstream input;
	input.open("pilot_routes.txt");

	ofstream output;
	output.open("pilot_areas.txt");

	string name;
	float area;
	float numbers_x[15] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
	float numbers_y[15] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
  
	while (input)
	{
		read(input, name, numbers_x, numbers_y);
		area = calculate(numbers_x, numbers_y);
		write(output, name, area);
	}

	output.close();

	return 0;
}

void read(static ifstream & input, string & pilot, float x[], float y[])
{
	int i;
	char comma;

	input >> pilot;

	for (i = 0; i < 15; i++)
	{
		input >> x[i];
		input >> comma;
		input >> y[i];
	}
}

float calculate(float x[], float y[])
{
	float size, result, num1, num2, num3, num4, num5, num6, num7, num8, num9, num10, num11, num12, num13, num14;
	int i;

	for (i = 0; i < 14; i++)
	{
		result = (x[i] * y[i + 1]) - (y[i] * x[i + 1]);

		if (i == 0)
			num1 = result;
		else if (i == 1)
			num2 = result;
		else if (i == 2)
			num3 = result;
		else if (i == 3)
			num4 = result;
		else if (i == 4)
			num5 = result;
		else if (i == 5)
			num6 = result;
		else if (i == 6)
			num7 = result;
		else if (i == 7)
			num8 = result;
		else if (i == 8)
			num9 = result;
		else if (i == 9)
			num10 = result;
		else if (i == 10)
			num11 = result;
		else if (i == 11)
			num12 = result;
		else if (i == 12)
			num13 = result;
		else
			num14 = result;
	}

	result = (num1 + num2 + num3 + num4 + num5 + num6 + num7 + num8 + num9 + num10 + num11 + num12 + num13 + num14) / 2;

	if (result >= 0)
		size = result;
	else
		size = result * -1;

	return size;
}

void write(static ofstream & output, string fighter, float patrol_area)
{
	output << fighter << "\t" << setprecision(2) << showpoint << fixed << patrol_area << endl;
}
I found some problem in read function below:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
void read(static ifstream & input, string & pilot, float x[], float y[])
{
	int i;
	char comma;

	input >> pilot;

	for (i = 0; i < 15; i++)
	{
		input >> x[i];
		input >> comma;
		input >> y[i];
	}
}


I noticed that in each cycle of the loop, you are going to get the pair of values representing a coordinate. As you can see in the format of your input file, in every line there is a name and 5 pairs of coordinate x and y but why the loop is up to 15? For me it has to be 5 only. Check it out.
Topic archived. No new replies allowed.