My goal is to read Olympic data into an array of structs. What i need to read in is the country code, and number of gold, silver or bronze medals that the country won. Also if one country won more than one medal, i am to just increment the information already read in on that country. My problem is that i cant get the function to overlap and just increment instead of just reading it into the next array index.
sample input file:
1987 100_Men Tom Burke GOLD USA 12.0
1875 100_Men Frits Hofman SILVER DEU 12.2
1958 100_Men Francis Lane BRONZE USA 12.6
1928 100_Men Elizabeth Robinson GOLD USA 12.2
......
my function code
SIZE is a const of 30 which is the max of countries and i initialized all the array members of nation to "xxx"
struct Data
{
string nation;
int award1;
int award2;
int award3;
};
void arryRead(Data ary[SIZE])
{
int year;
string event, firstName, lastName, medal, country, inputFile;
double time;
bool flag = true;
ifstream inFile;
while (flag == true)
{
cout << endl << "Enter file name: ";
cin >> inputFile;
cout << endl;
inFile.open(inputFile.c_str());
if (!inFile)
{
cout << "Cannot open the input file. Try agin." << endl;
}
else
{
flag = false;
}
}
while (!inFile.eof())
{
inFile >> year >> event >> firstName >> lastName >> medal
>> country >> time;
for(int g = 0; g < SIZE; g++)
{
if (ary[g].nation == country)
{
if (medal == "GOLD")
ary[g].award1++;
else if (medal == "SILVER")
ary[g].award2++;
else if (medal == "BRONZE")
ary[g].award3++;
}//end if statment
if (ary[g].nation == "xxx")
{
ary[g].nation = country;
if (medal == "GOLD")
ary[g].award1++;
else if (medal == "SILVER")
ary[g].award2++;
else if (medal == "BRONZE")
ary[g].award3++;
break;
}
}
}//end while loop
inFile.close();
cout << ary[0].nation << endl << ary[1].nation << ary[2].nation << ary[3].nation
<< ary[4].nation << ary[5].nation << ary[6].nation << ary[7].nation;
}//end function
any help would be appreciated
entire code is in attachment