I'm about to pull my hair out working on this program. I'm close! I think....I just have a stack overflow error to work around. Here is the code:
using namespace std;
struct runner{
public:
int position;
string time;
int age;
string sex;
string gender;
string firstName;
string lastName;
string city;
string state;
runner(){
runner r1;
string dataChunk;
int ageTotal = 0;
double ageAverage = 0.0;
int ageCount = 0;
int femaleAlabama = 0;
int femaleOverForty = 0;
int femaleHuntsville = 0;
int femaleCount = 0;
double femaleAgeAverage = 0.0;
ifstream inFile("C:\\Users\\Anthony\\Desktop\\cmarathon.csv");
getline(inFile, dataChunk, ',');
r1.position = atoi(dataChunk.c_str());
getline(inFile, dataChunk, ',');
r1.time = dataChunk;
getline(inFile, dataChunk, ',');
r1.age = atoi(dataChunk.c_str());
ageTotal = +age;
ageCount = +1;
getline(inFile, dataChunk, ',');
r1.sex = dataChunk;
if(sex == "f" || "F")
femaleCount++;
femaleAgeAverage++;
getline(inFile, dataChunk, ',');
r1.gender = dataChunk;
getline(inFile, dataChunk, ',');
r1.firstName = dataChunk;
getline(inFile, dataChunk, ',');
r1.lastName = dataChunk;
getline(inFile, dataChunk, ',');
r1.city = dataChunk;
getline(inFile, dataChunk, ',');
r1.state = dataChunk;
if(sex == "f" || "F" && age > 40)
femaleOverForty++;
if(sex == "f" || "F" && city == "Huntsville")
femaleHuntsville++;
if(sex == "f" || "F" && state == "Al" || "AL")
femaleAlabama++;
cout<<r1.position<<" "<<r1.time<<" "<<r1.age<<" "<<r1.sex<<" "
<<r1.gender<<" "<<r1.firstName<<" "<<r1.lastName<<" "<<r1.city
<<" "<<r1.state<<endl;}
};
int main(){
int i;
for(i = 1; i <1343; i++){
runner();
}
system("PAUSE");
return 0;
}
The goal here is to loop through a .csv sheet and pull the data into a structure. Then I can use that data to calculate various things like average age of females etc etc. Any suggestions?
EDIT:
Here is a snippet of the error code I receive when I try to run the program