Array code

I am trying to run a program that will be able to calculate the average employment rate form the data that is read from the text. When the program executes, it displays the following regardless of whether I have the file employed_15-24yrsOld.txt save onto the computer or not:

Cannot open the input file: ch8_Ex13Data.txt.
Program terminates!

The following is a .txt file (I know this is long):

Australia 62.7 62.1 63.3 59.7
Austria 0 52.8 53.1 54.6
Belgium 30.4 30.3 27.5 25.3
Canada 61.3 56.2 57.7 54.5
Chile 0 26.4 25.4 31.1
CzechRepublic 0 38.3 27.3 25.2
Denmark 65.0 67.1 62.3 55.0
Estonia 51.7 32.9 29.8 34.3
Finland 55.2 42.9 42.1 43.3
France 35.7 28.3 30.2 28.8
Germany 56.4 47.2 42.6 46.6
Greece 30.3 26.9 25.0 13.1
Hungary 0 32.5 21.8 18.6
Iceland 0 68.2 71.6 66.0
Ireland 41.4 49.3 47.8 27.9
Israel 23.6 28.2 26.6 43.5
Italy 29.8 27.8 25.5 20.5
Japan 42.2 42.7 40.9 38.5
Korea 32.5 29.4 29.9 24.2
Luxembourg 43.3 31.8 24.9 21.7
Mexico 0 48.9 43.7 43.1
Netherlands 54.5 66.5 61.7 63.3
NewZealand 59.1 54.2 56.4 49.5
Norway 53.4 58.1 52.9 52.7
Poland 0 24.5 20.9 24.7
Portugal 51.2 41.8 36.1 23.6
SlovakRepublic 0 29.0 25.6 20.1
Slovenia 0 0 34.1 27.3
Spain 38.3 36.3 41.9 20.0
Sweden 66.1 46.7 43.3 40.0
Switzerland 0 65.1 59.9 61.7
Turkey 45.9 37.0 30.2 31.5
UnitedKingdom 70.1 61.5 58.7 50.0
UnitedStates 59.8 59.7 53.9 46.0
Brazil 0 0 52.7 50.0
China 0 61.9 0 53.7
India 0 0 0 33.1
Indonesia 0 0 0 0
RussianFederation 0 34.3 33.1 33.7
SouthAfrica 0 0 15.0 12.2


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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
  /*
this program should calculate country’s average employment rate for age
group persons of 15-24 in employment years 1990, 2000, 2005 and 2012. it uses three arrays: a one-dimensional array to store the country’s names, a (parallel) two-dimensional array to store the average employment rate, and a parallel one-dimensional array to store the percentage of population data.
The percentage of population data is provided in the attached file
“employed_15_24yrsOld.txt”.
*/

#include <iostream>
#include <fstream>
#include <string>
#include <iomanip>

using namespace std;
const int SIZE = 40;		//declaring SIZE as a constant integer of 40
const int COLUMN = 5;		//declaring COLUMN as a constant integer of 5
void getData(ifstream& , string [], double [][COLUMN]);		//function prototypes defined
void calculateAverage(double [][COLUMN], int);
void calculateGrade(double [][COLUMN], char [], int );
void print(string[], double [][COLUMN], char [], int);
  
int main()
{	//arrays and variables declared
	string names[SIZE];
    double testData[SIZE][COLUMN];
    char grade[SIZE];

    ifstream inFile;
    
	//unable to open file
    inFile.open("employed_15-24yrsOld.txt", ios::in);  //opens file "employed_15-24yrsOld.txt" durring execution   

    if (!inFile.eof())   //original expression: if(!infile)   //program teminates if filemaneis incorrect
    {	
        cout << "Cannot open the input file: ch8_Ex13Data.txt." << endl;
        cout << "Program terminates!" << endl;
        return 1;
    }

    cout << fixed << showpoint << setprecision(2);  //fixes values to two decimal places. 


    getData(inFile, names, testData);	//calling functons defined
    calculateAverage(testData, SIZE);
    calculateGrade(testData, grade, SIZE);
    print(names, testData, grade, SIZE);

    inFile.close();

	return 0;
}

///////////////////////////////////////////////////////////////////////
//
// Function: getData
//
// Description:
// This function reads and store data into arrays.
//
// Parameters:
// ifstream& inf: refers to the filename, a call by reference
// string n[]: name of country
// double tstData[][COLUMN]: employment rate
//
///////////////////////////////////////////////////////////////////////
void getData(ifstream& inf, string n[], double tstData[][COLUMN])
{
    int	count=0;

	while (!inf.eof())
	{
		inf>>n[count]>>tstData[count][1]>>tstData[count][2]>>tstData[count][3]>>tstData[count][4];	
		
		count=count+1;
	}
	
}

///////////////////////////////////////////////////////////////////////
//
// Function: calculateAverage
//
// Description:
// This functon calulate average employment rate
//
// Parameters:
// double tstData[][COLUMN]: employment rate
// int count: number of rows to be averaged
//
///////////////////////////////////////////////////////////////////////
void calculateAverage(double tstData[][COLUMN],int count)
{
	int i;
	int j;

	for(j=0; j<count; j++)
	{
		double sum=0;

		for(i=1;i < COLUMN; i++)
		{
			sum=sum+tstData[j][i];
		}	
		tstData[j][0]=sum/4;
	}
}

///////////////////////////////////////////////////////////////////////
//
// Function: calculateGrade
//
// Description:
// this program determines grade based on a range, that is the calculated average employment rate
// ex:
// Average employment rate > 80, N - Relatively no risk
// Average employment rate between 60- 79, L - Relatively low risk
// Average employment rate between 50 and 59, R - Relatively at risk
// Average employment rate below 50, H - Relatively high risk
//
// Parameters:
// double tstData[][COLUMN]: employment rate
// char gr[]: grade based on partucular range, that is average employment rate
// int count: number of rows
//
///////////////////////////////////////////////////////////////////////
void calculateGrade(double tstData[][COLUMN], char gr[], int count)
{
	int i;
	int j;	
				//SIZE
	for(i=0;i<count;i++)
	{
		if(tstData[i][0]>80)
			gr[i]='N';  
		else if (tstData[i][0] && tstData[i][0] < 80)	
			gr[i]='L';
		else if (tstData[i][0] && tstData[i][0] < 60)	
			gr[i]='R';
		else
			gr[i]='H';
	
		for(j=1;j<COLUMN;j++)		
		{		
		if(tstData[i][0])
			gr[i]='N';
		else if (tstData[i][0]>=60 && tstData[i][0]< 80)	
			gr[i]='L';
		else if (tstData[i][0]>=50 && tstData[i][0]< 60)	
			gr[i]='R';
		else
		    gr[i]='H';
		}
    }
}

///////////////////////////////////////////////////////////////////////
//
// Function:  print
//
// Description:
// this function displays the output of the results
//
// Parameters:
// string n[]: name of country
// double tstData[SIZE][COLUMN]: employment rate
// char gr[]: grade based on partucular range, that is average employment rate
// int count: number of rows
//
//
///////////////////////////////////////////////////////////////////////
void print(string n[], double tstData[SIZE][COLUMN], char gr[], int count)
{

	int i;
	cout<<"Name"<<"                   "<<"1990"<<"     "<<"2000"<<"     "<<"2005"<<"     "<<"2012"<<"     "<<"Average"<<"     "<<"Grade"<<endl;	
	cout<<n[count]<<"                   "<<tstData[count][1]<<"     "<<tstData[count][2]<<"     "<<tstData[count][3]<<"     "<<tstData[count][4]<<"     "<<tstData[count][5]<<"     "<<gr<<endl;
	for(i=0;i<COLUMN;i++)
		cout<<n[count]<<"                   "<<tstData[count][1]<<"     "<<tstData[count][2]<<"     "<<tstData[count][3]<<"     "<<tstData[count][4]<<"     "<<tstData[count][5]<<"     "<<gr<<endl; 
}


I am trying to output the following.

Name			1990	2000	2005	2012	Average	     Grade
Australia		62.7	62.1	63.3	59.7	49.56		L
Austria			0	52.8	53.1	54.6	32.1		H
Belgium			30.4	30.3	27.5	25.3	22.7		H
Canada			61.3	56.2	57.7	54.5	45.94		R
Chile			0	26.4	25.4	31.1	16.58		H
CzechRepublic		0	38.3	27.3	25.2	18.16		H
Denmark			65	67.1	62.3	55	49.88		L
Estonia			51.7	32.9	29.8	34.3	29.74		H
Finland			55.2	42.9	42.1	43.3	36.7		H
France			35.7	28.3	30.2	28.8	24.6		H
Germany			56.4	47.2	42.6	46.6	38.56		H
Greece			30.3	26.9	25	13.1	19.06		H
Hungary			0	32.5	21.8	18.6	14.58		H
Iceland			0	68.2	71.6	66	41.16		R
Ireland			41.4	49.3	47.8	27.9	33.28		H
Israel			23.6	28.2	26.6	43.5	24.38		H
Italy			29.8	27.8	25.5	20.5	20.72		H
Japan			42.2	42.7	40.9	38.5	32.86		H
Korea			32.5	29.4	29.9	24.2	23.2		H
Luxembourg		43.3	31.8	24.9	21.7	24.34		H
Mexico			0	48.9	43.7	43.1	27.14		H
Netherlands		54.5	66.5	61.7	63.3	49.2		L
NewZealand		59.1	54.2	56.4	49.5	43.84		R
Norway			53.4	58.1	52.9	52.7	43.42		R
Poland			0	24.5	20.9	24.7	14.02		H
Portugal		51.2	41.8	36.1	23.6	30.54		H
SlovakRepublic		0	29	25.6	20.1	14.94		H
Slovenia		0	0	34.1	27.3	12.28		H
Spain			38.3	36.3	41.9	20	27.3		H
Sweden			66.1	46.7	43.3	40	39.22		H
Switzerland		0	65.1	59.9	61.7	37.34		H
Turkey			45.9	37	30.2	31.5	28.92		H
UnitedKingdom		70.1	61.5	58.7	50	48.06		L
UnitedStates		59.8	59.7	53.9	46	43.88		R
Brazil			0	0	52.7	50	20.54		H
China			0	61.9	0	53.7	23.12		H
India			0	0	0	33.1	6.62		H
Indonesia		0	0	0	0	0		H
RussianFederation	0	34.3	33.1	33.7	20.22		H
SouthAfrica		0	0	15	12.2	5.44		H

Group Age 15-24 Years Old Employment Average: 35.24
Press any key to continue... 


Any suggestions will be appreciated :)
The file employed_15-24yrsOld.txt is not where the program expects it.
For testing better use an absolute path.
Topic archived. No new replies allowed.