Guys,
Im not very experienced in C++. I was practicing problems from topcoder to improve my knowledge in C++. I've posted the code i used for solving a problem statement given by topcoder website. The compiler tells that there is a linking error with this code and hence its not compiling properly. Plz help me out.
#include<iostream.h>
#include<string.h>
using namespace std;
class HowEasy
{
public:
string statement;
int flag,letterCount,wordCount;
int pointVal (string);
};
int pointVal (string s)
{
int len = s.length();
int avgCount,flag=0,i,wordCount=0,letterCountMain=0,letterCountTemp=0;
for(i=0; i<len ;i++)
{
//if((int(s[i]>=65) && int(s[i]<=90)) || int((s[i]>=97) && int(s[i]<=122)))
if(((s[i]>=65)&&(s[i]<=90))||((s[i]>=97)&&(s[i]<=122)))
{
if(flag==0)
{
letterCountTemp+=1;
}
}
else
{
flag=1;
letterCountTemp=0;
}
if(s[i]==' ')
{
if(flag==0)
{
letterCountMain+=letterCountTemp;
wordCount+=1;
}
flag=0;
}
if(s[i]=='.')
{
if(flag==0 && s[i+1]!='.')
{
letterCountMain+=letterCountTemp;
wordCount+=1;
}
flag=0;
}
}
cout << "The no of letters in the problem statement is displayed below: " << letterCountMain << endl;
cout << "The no of words in the problem statement is displayed below: " << wordCount << endl;
avgCount = letterCountMain/wordCount;
cout << "The avg letter count in the problem statement is displayed below: " << avgCount << endl << endl;
if(avgCount<=3)
{
return 250;
}
else if((avgCount==4)||(avgCount==5))
{
return 500;
}
else if(avgCount>6)
{
return 1000;
}
}
int main()
{
HowEasy class1;
char t;
cout << "Press any key to type the problem statement: ";
cin >> t;
cin.get();
cout << "Type the problem statement: ";
getline(cin, class1.statement);
cout << "The problem statement's point value is :" << class1.pointVal(class1.statement);
}