Sorry to dump ~20 lines of code on you guys, but this is a function from a bigger program I'm working on that counts votes from a text file.
The file goes like so: it starts with an ID, ten Y/N votes on bills, and then a vote on a new captain (it's a pirate themed problem, I guess).
Example:
2YNYNYNYNYNThe New Guy
4YYYYYYNNYYThe Captain
29YYYYYYNYYNThe Captain
etc.
I've stored the votes in an array of strings called lineNoDupes. The array of chars called filecontents searches each string character by character in order to increment votes, and this particular function counts the votes for "The New Guy" or "The Captain".
My problem is that the for loop in the beginning of the function does not start. The cout in the beginning is to make sure the function is being called successfully, which it is.
I am using a lot of global variables just for convenience's sake.
void countElections()
{
cout << "countElections();\n";
char filecontents[20];
for( int i = 0; i < numElements; i++ )
{
strcpy( filecontents, lineNoDupes[i].c_str() );
if( i < 8 ) //the first 8 elements have single digit IDs, so they're tested differently
{
cout << filecontents[15] << endl; //filecontents[15] is where the N or C will be in the candidate name
if( filecontents[15] == 'N' ) //no need to test more than the 'N' in new guy or 'C' in captain
newGuyVotes++;
elseif( filecontents[15] == 'C' )
captainVotes++;
}
if( i > 8 ) //these are all double digit IDs
{
if( filecontents[16] == 'N' ) //no need to test more than the 'N' in new guy or 'C' in captain
newGuyVotes++;
elseif( filecontents[16] == 'C' )
captainVotes++;
}
}
cout << "CAPTAIN VOTES: " << captainVotes << "\n";
cout << "NEW GUY VOTES: " << newGuyVotes << "\n";
}
void countAmendments()
{
cout << "countAmendments();\n";
char filecontents[20];
for( int i = 0; i < numElements; i++ )
{
strcpy( filecontents, lineNoDupes[i].c_str() );
if( i < 8 ) //the first 8 elements have one digit IDs and are tested differently
{// I understand that the y variable is obtuse, but it just counts from 1 to 10 without involving a third loop
for( int j = 1, y = 2; j < 20; j++, y+=2 )
{
if( filecontents[j] == 'Y' )
AmY[(y/2)-1]++;
elseif( filecontents[j] == 'N' )
AmN[(y/2)-1]++;
}
}
if( i > 8 ) //these are all double digit IDs
{
for( int j = 2, y = 2; j < 20; j++, y+=2 )
{
if( filecontents[j] == 'Y' )
AmY[(y/2)-1]++;
elseif( filecontents[j] == 'N' )
AmN[(y/2)-1]++;
}
}
}
for( int i = 0; i < 10; i++ )
cout << AmY[i] << "\t";
cout << "\n";
for( int i = 0; i < 10; i++ )
cout << AmN[i] << "\t";
}
Also, I edited out numElements and replaced it with the number 55. The loop still does not run. I tried doing a cout in the first line of the loop to verify whether or not the loop was running, and it did not print anything. So the loop itself is not even starting.