int main()
{
vector<float>times;
vector<int>bins;
float y =0;
float time;
int aCount =0;
float binSize = 0.39;
float mean;
float x = binSize;
int numberOfBins;
float binMean =0;
vector<float>values;
vector<string>fileNames;
vector<int>pos;
pos.push_back(0);
cout<<"********************************TamStar 1.0********************************\n"
<< "Welcome to TamStar please create a file called TamStar in your C:"
<< "drive and name our txt file TamStar before begining analysis"<< "\n\n";
cout<< "What would you like your mean to be?" << endl;
cin>> mean;
ifstream in;
in.open("C:\\TamStar\\TamStar.txt" );
string jack;
string jackOld;
float jill= 0;
float jillOld =0;
in>> jack >> jill;
jackOld=jack;
jillOld=jill;
values.push_back(jill);
/*
This is the Fileuploading portion The user deamed
that they wanted one long collum and the position
are pushed back on to a vector to create itterato
rs later
*/
while(in >> jack >> jill )
{
if(jackOld!=jack)
{
fileNames.push_back(jackOld);
pos.push_back(values.size()-1);
}
values.push_back(jill);
jackOld = jack;
jillOld = jill;
}
fileNames.push_back(jackOld);
cout<< "values.size(),fileNames.size(): " << values.size()<<"," << fileNames.size() << endl;
/*
The Ka for loop uses the positions to take the
portions of the file that we want and analyze
files one at a time outputting them later
*/
for(int ka =0; ka<pos.size()-1; ++ka)
{
int vBegin = pos[ka];
int vEnd = pos[ka+1];
times.clear();
bins.clear();
times.resize(vEnd-vBegin+1);
copy(values.begin()+vBegin,values.begin()+vEnd,times.begin());
sort(times.begin(),times.end());
binSize = (times.back()/times.size())*mean;
x = binSize;
y = 0;
aCount= 0;
// Algorithim
for(int i =0; i<times.size(); ++i)
{
if(times[i]>=y && times[i]<=x)
{
++aCount;
if(i==times.size()-1)
{
bins.push_back(aCount);
}
}
else
{
while(times[i]>=x)
{
bins.push_back(aCount);
x =x+binSize;
y =y+binSize;
aCount =0;
if(times[i]>=y && times[i]<=x)
{
++aCount;
}
}
if(i==times.size()-1)
{
bins.push_back(aCount);
}
}
}
/*
Calculates Bin Mean
*/
binMean=0;
for(int i =0; i<bins.size(); ++i)
{
binMean = binMean+bins[i];
if(i == bins.size()-1)
{
binMean = binMean/bins.size();
}
}
/*
This is the statistical output
*/
cout<< ka <<": "<< fileNames[ka]<< " Mean: " << binMean << "\n";
std::sort (bins.begin(), bins.end());
vector< vector<int> > binCount(bins.size(), vector<int>(bins.size()));
// WHERE ERORR IS OCCURING
for(int j=0; j<=bins.back(); j++)
{
int mycount;
mycount = (int) count(bins.begin(), bins.end(),j);
binCount[j][0]=j;
binCount[j][1]= mycount;
}
/*
The Data Output to a txt File
*/
ofstream myfile;
myfile.open ("TamStarOutput.txt",ios::app);
myfile<< fileNames[ka] << endl;
for(int i=0; i<=bins.back(); ++i)
{
myfile<< binCount[i][0] << " appeared: " << binCount[i][1] << endl;
}
myfile.close();
}
in.close();
for(int i=0; i<fileNames.size(); i++)
{
cout<< i << "."<< fileNames[i] << endl;
}
cout<< "Your Program is complete thank you for choosing TamStar drive safely"
<< endl;
}
The for loop at line 144 which is indicated by the comment in caps "WHERE ERROR IS OCCURING", is indexing a vector out of its range in a particular instance.
The paramater that the user has control over is the binMean the user has a choice of making it any whole integer.
My error is occuring when I change the mean from "1" to '2' or '3'. I'm sure it is an indexing problem.