Old assignment

This an old assignment from last week. I was wondering if anyone could help me understand what it is exactly that I done wrong. The program was supposed to read from a file that contained two things, a district number and either a Y or N to represent a vote. I got it to output for the most part but instead of counting how many individual votes for each district and then the over all total votes, it gave me some just out there numbers. Here is the code:

#include <iostream>
#include <iomanip>
#include <fstream>

using namespace std;

int main()
{

//declare variable and get input

ifstream inFile;
ofstream outFile;


char vote;
char district;
int totalYV;
int totalNV;
int d1TotalY; //do this for all districts
int d2TotalY;
int d3TotalY;
int d1TotalN;
int d2TotalN;
int d3TotalN;

inFile.open("vote.txt");
outFile.open("votersTotal.txt");

inFile >> district >> vote;

while(inFile)
{ inFile >> district >> vote;


// add in overall total for both

if(district=='1')
{if(vote=='Y')
d1TotalY==1;
totalYV = d1TotalY++;

}
else if(vote=='N')
{
d1TotalN==1;
totalNV = d1TotalN++;
}

if(district=='2')
{if(vote=='Y')
d2TotalY==1;
totalYV = d2TotalY++;
}
else if(vote=='N')
{
d2TotalN==1;
totalNV = d2TotalN++;
}
if(district=='3')
{if(vote=='Y')
d3TotalY==1;
totalYV = d3TotalY++;
}
else if(vote=='N')
{
d3TotalN==1;
totalNV = d3TotalN++;
}


totalYV++;
totalNV++;

};

outFile << "District 1 Y votes: " << d1TotalY << endl;
outFile << "District 1 N votes: " << d1TotalN << endl;
outFile << "District 2 Y votes: " << d2TotalY << endl;
outFile << "District 2 N votes: " << d2TotalN << endl;
outFile << "District 3 Y votes: " << d3TotalY << endl;
outFile << "District 3 N votes: " << d3TotalN << endl;
outFile << "Total Y Votes: " << totalYV << endl;
outFile << "Total N Votes: " << totalNV << endl;

inFile.close();
outFile.close();

return 0;
}
Topic archived. No new replies allowed.