?
2009-09-27 11:31:20 UTC
004566577
Prescott Schultz
86
003455675
Allison Dold
88
003455676
Brian Cantrell
87
003455467
Carrie Sutton
78
003455678
Zoe Ruedemann
89
003455678
Steven Allard
23
Each block of data is in order: Student ID, Student Name and Student's Test Score. I need to sum up the student's test scores so I can make an average of them. The problem I am running into is when using the atoi() function. The score line is being read into the main function as a string. When using atoi() to convert the score from string to int, I get this error:
error C2664: 'atoi' : cannot convert parameter 1 from 'std::string' to 'const char *'
1> No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
I have no issues getting the string values and am able to parse the data into appropriate functions, but in order to get the average of the scores I must be able to convert the score from type string to type int. Here is where the problem is in my code (the arrows marks the spot):
while( !records.eof() )
{
int i=0;
for (i=0; i<1; i++){
std::getline (records, line);
std::getline (records, line2);
std::getline (records, line3);
std::getline (records, line4);
string id = line;
string name = line2;
string score = line3;
--> int scoreVal = atoi(score);
--> total = scoreVal + total;
cout << "id: " << id << endl;
cout << "name: " << name << endl;
cout << "the score: " << score << endl;
cout << line4 << endl;
}
loop++;
}
All I'm trying to do is sum up the score values read in from the file so that I can divide them by the sample size to get the average.
Any help is appreciated thanks.