I have an error in my program which says that
‘count’ cannot be used as a function.
it points to the below line
mycount = (int) count (t1q1.begin(), t1q1.end(), 1);
i have already included algorithm, using namespace std, but still it shows the error.
This is what I do with my vector t1q1
The below code allows the program to read in the file and extract the certain information and push it back to the vector
MY FUNCTION TO READ FILE AND STORE IT IN VARIABLES
void checkForAnswers(char *ptr)
{
char String[256];
int count = 0;
while ( *ptr != ':')
{
String[count] = *ptr;
ptr++;
count++;
}
String[count] = '\0';
//if topic is 1.
if (strcmp(String, "1") == 0)
{
currentPtr=Travels(':',startPtr);
int answerone1 = (int)atoi(currentPtr);
currentPtr=Travels(':',currentPtr);
int answertwo2 = (int)atoi(currentPtr);
currentPtr=Travels(':',currentPtr);
int answerthree3 = (int)atoi(currentPtr);
currentPtr=Travels(':',currentPtr);
int answerfour4 = (int)atoi(currentPtr);
currentPtr=Travels(':',currentPtr);
int answerfive5 = (int)atoi(currentPtr);
t1q1.push_back(answerone1);
t1q2.push_back(answertwo2);
t1q3.push_back(answerthree3);
t1q4.push_back(answerfour4);
t1q5.push_back(answerfive5);
}
if (strcmp(String, "2") == 0)
{
currentPtr=Travels(':',startPtr);
int answerone1 = (int)atoi(currentPtr);
currentPtr=Travels(':',currentPtr);
int answertwo2 = (int)atoi(currentPtr);
currentPtr=Travels(':',currentPtr);
int answerthree3 = (int)atoi(currentPtr);
currentPtr=Travels(':',currentPtr);
int answerfour4 = (int)atoi(currentPtr);
currentPtr=Travels(':',currentPtr);
int answerfive5 = (int)atoi(currentPtr);
t2q1.push_back(answerone1);
t2q2.push_back(answertwo2);
t2q3.push_back(answerthree3);
t2q4.push_back(answerfour4);
t2q5.push_back(answerfive5);
}
if (strcmp(String, "3") == 0)
{
currentPtr=Travels(':',startPtr);
int answerone1 = (int)atoi(currentPtr);
currentPtr=Travels(':',currentPtr);
int answertwo2 = (int)atoi(currentPtr);
currentPtr=Travels(':',currentPtr);
int answerthree3 = (int)atoi(currentPtr);
currentPtr=Travels(':',currentPtr);
int answerfour4 = (int)atoi(currentPtr);
currentPtr=Travels(':',currentPtr);
int answerfive5 = (int)atoi(currentPtr);
t3q1.push_back(answerone1);
t3q2.push_back(answertwo2);
t3q3.push_back(answerthree3);
t3q4.push_back(answerfour4);
t3q5.push_back(answerfive5);
}
currentPtr=0;
}
MY MAIN
char Lines1[256];
int count1 = 0;
ifstream resultfile("results.txt");
if (resultfile.is_open())
{
do
{
resultfile.getline(Lines1, 256);
startPtr = Lines1;
checkForAnswers(startPtr);
count1++;
}while(resultfile.eof() == false);
resultfile.close();
}
int mycount;
cout<< "\n";
cout<< "TABULATION RESULTS\n";
cout<< "------------------\n";
cout<< "Topic 1, Question 1\n";
mycount = (int) count (t1q1.begin(), t1q1.end(), 1);
cout<< "Option 1: "<< mycount << " time(s)\n";
Hope you guys will be able to help me out.
Thanks in advance to those who helped!
🙂
In your code
countrefers to the local variablecount, which has typeintand thus cannot be used as a function. You should name the variable something else or refer to the function using its qualified namestd::count.Also make sure that you
#include <algorithm>(and have an appropriateusingdeclaration if you go the route of renaming the variable and calling the function using its unqualified name).