Skip to content

Instantly share code, notes, and snippets.

@RSquaredSoftware
Last active December 27, 2015 20:09
Show Gist options
  • Save RSquaredSoftware/7382085 to your computer and use it in GitHub Desktop.
Save RSquaredSoftware/7382085 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <fstream>
using namespace std;
int main() {
// The first character
char voter;
char lastVoter;
// The 8 Y/N votes
char choiceOne;
char choiceTwo;
char choiceThree;
char choiceFour;
char choiceFive;
char choiceSix;
char choiceSeven;
char choiceEight;
// The candidate they vote for
string candidateNameF;
string candidateNameM;
string candidateNameL;
// Open the ballots and counted files
std::ifstream ballotFile("ballots.txt");
std::ofstream countedFile("counted.txt");
while(ballotFile.good()) {
ballotFile >> voter
>> choiceOne
>> choiceTwo
>> choiceThree
>> choiceFour
>> choiceFive
>> choiceSix
>> choiceSeven
>> choiceEight
>> candidateNameF
>> candidateNameM;
// These guys have a last name so make a special case. Not the best way to do this.
if (candidateNameM == "Black" || candidateNameM == "Legs")
ballotFile >> candidateNameL;
// If the voter is a repeat, continue
if (voter == lastVoter)
continue;
// For testing purposes
std::cout << voter << " " << choiceOne << " " << choiceTwo << " "
<< choiceThree << " " << choiceFour << " " << choiceFive << " "
<< choiceSix << " " << choiceSeven << " " << choiceEight << " "
<< candidateNameF << " " << candidateNameM << " " << candidateNameL
<< std::endl;
// Stream the file out
countedFile << voter << " " << choiceOne << " " << choiceTwo << " "
<< choiceThree << " " << choiceFour << " " << choiceFive << " "
<< choiceSix << " " << choiceSeven << " " << choiceEight << " "
<< candidateNameF << " " << candidateNameM << " " << candidateNameL
<< "\n";
// Housekeeping in the loop
lastVoter = voter;
candidateNameL = "";
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment