Ok, here is the whole code that I have came up with along with some help from others, and it will not work. Does anyone see anything in this code that is the hitch(s). The program will compile and link just wont do anything after it prompts the user to enter filenames. Please help in anyway you can, I am really stressing here! Thanks
Code:
#include <iostream>
#include <fstream>
#include<string>
#include<cstddef>
#include<iomanip>
using namespace std;
struct candInfo
{
string lastName;
string firstName;
int Reg1;
int Reg2;
int Reg3;
int Reg4;
int total;
};
int main()
{
ifstream inFile1, inFile2;
candInfo One, Two, Three, Four, Five, Six;
string fileName1, fileName2;
cout << "Enter name of file containing Candidate Names: ";
cin >> fileName1;
if (fileName1.fail()){
cout<<"ERROR! Input file not found, (location?)\n";
cout<<"Program Terminated\n";
exit(1);
inFile1.open(fileName1.c_str());
inFile1>>One.lastName;
inFile1>>One.firstName;
inFile1>>Two.lastName;
inFile1>>Two.firstName;
inFile1>>Three.lastName;
inFile1>>Three.firstName;
inFile1>>Four.lastName;
inFile1>>Four.firstName;
inFile1>>Five.lastName;
inFile1>>Five.firstName;
inFile1>>Six.lastName;
inFile1>>Six.firstName;
cout << "Enter name of file containing voting results: ";
cin >> fileName2;
if (fileName2.fail()){
cout<<"ERROR! Input file not found, (location?)\n";
cout<<"Program Terminated\n";
exit(1);
inFile2.open(fileName2.c_str());
int numReg, numVotes;
string namCan;
One.Reg1=One.Reg2=One.Reg3=One.Reg4=One.total=0;
Two.Reg1=Two.Reg2=Two.Reg3=Two.Reg4=Two.total=0;
Three.Reg1=Three.Reg2=Three.Reg3=Three.Reg4=Three.total=0;
Four.Reg1=Four.Reg2=Four.Reg3=Four.Reg4=Four.total=0;
Five.Reg1=Five.Reg2=Five.Reg3=Five.Reg4=Five.total=0;
Six.Reg1=Six.Reg2=Six.Reg3=Six.Reg4=Six.total=0;
while(namCan != "end")
{
inFile2>>namCan;
inFile2>>numReg;
inFile2>>numVotes;
switch(numReg)
{
case 1:
One.Reg1+=numVotes;
break;
case 2:
One.Reg2+=numVotes;
break;
case 3:
One.Reg3+=numVotes;
break;
case 4:
One.Reg4+=numVotes;
break;
}
}
if(namCan == Two.lastName)
{
inFile2>>namCan;
inFile2>>numReg;
inFile2>>numVotes;
{
switch(numReg)
{
case 1:
Two.Reg1+=numVotes;
break;
case 2:
Two.Reg2+=numVotes;
break;
case 3:
Two.Reg3+=numVotes;
break;
case 4:
Two.Reg4+=numVotes;
break;
}
}
if(namCan == Three.lastName)
{
inFile2>>namCan;
inFile2>>numReg;
inFile2>>numVotes;
switch(numReg)
{
case 1:
Three.Reg1+=numVotes;
break;
case 2:
Three.Reg2+=numVotes;
break;
case 3:
Three.Reg3+=numVotes;
break;
case 4:
Three.Reg4+=numVotes;
break;
}
}
if(namCan == Four.lastName)
{
inFile2>>namCan;
inFile2>>numReg;
inFile2>>numVotes;
switch(numReg)
{
case 1:
Four.Reg1+=numVotes;
break;
case 2:
Four.Reg2+=numVotes;
break;
case 3:
Four.Reg3+=numVotes;
break;
case 4:
Four.Reg4+=numVotes;
break;
}
}
if(namCan == Five.lastName)
{
inFile2>>namCan;
inFile2>>numReg;
inFile2>>numVotes;
switch(numReg)
{
case 1:
Five.Reg1+=numVotes;
break;
case 2:
Five.Reg2+=numVotes;
break;
case 3:
Five.Reg3+=numVotes;
break;
case 4:
Five.Reg4+=numVotes;
break;
}
}
if(namCan == Six.lastName)
{
inFile2>>namCan;
inFile2>>numReg;
inFile2>>numVotes;
switch(numReg)
{
case 1:
Six.Reg1+=numVotes;
break;
case 2:
Six.Reg2+=numVotes;
break;
case 3:
Six.Reg3+=numVotes;
break;
case 4:
Six.Reg4+=numVotes;
break;
}
}
}
One.total=One.Reg1+One.Reg2+One.Reg3+One.Reg4;
Two.total=Two.Reg1+Two.Reg2+Two.Reg3+Two.Reg4;
Three.total=Three.Reg1+Three.Reg2+Three.Reg3+Three.Reg4;
Four.total=Four.Reg1+Four.Reg2+Four.Reg3+Four.Reg4;
Five.total=Five.Reg1+Five.Reg2+Five.Reg3+Five.Reg4;
Six.total=Six.Reg1+Six.Reg2+Six.Reg3+Six.Reg4;
cout<<setw(50)<<"---Election Results---"<<endl<<endl;
cout<<"Candidate Name" <<
setw(15)<<"Region1"<<setw(10)<<"Region2"<<setw(10)<<"Region3"<<setw(10)<<"Region4"<<
setw(10)<<"Total"<<endl;
cout<<"---------------" <<
setw(15)<<"--------"<<setw(10)<<"-------"<<setw(10)<<"-------"<<setw(10)<<"-------"<<
setw(10)<<"-------"<<endl;
cout<<Six.lastName<<
setw(6)<<Six.firstName<<setw(17)<<Six.Reg1<<setw(10)<<Six.Reg2<<
setw(10)<<Six.Reg3<<setw(10)<<Six.Reg4<<setw(10)<<Six.total<<endl;
cout<<Five.lastName<<
setw(6)<<Five.firstName<<setw(17)<<Five.Reg1<<setw(10)<<Five.Reg2<<
setw(10)<<Five.Reg3<<setw(10)<<Five.Reg4<<setw(10)<<Five.total<<endl;
cout<<Three.lastName<<
setw(6)<<Three.firstName<<setw(17)<<Three.Reg1<<setw(10)<<Three.Reg2<<
setw(10)<<Three.Reg3<<setw(10)<<Three.Reg4<<setw(10)<<Three.total<<endl;
cout<<One.lastName<<
setw(6)<<One.firstName<<setw(17)<<One.Reg1<<setw(10)<<One.Reg2<<
setw(10)<<One.Reg3<<setw(10)<<One.Reg4<<setw(10)<<One.total<<endl;
cout<<Two.lastName<<
setw(6)<<Two.firstName<<setw(17)<<Two.Reg1<<setw(10)<<Two.Reg2<<
setw(10)<<Two.Reg3<<setw(10)<<Two.Reg4<<setw(10)<<Two.total<<endl;
cout<<Four.lastName<<
setw(6)<<Four.firstName<<setw(17)<<Four.Reg1<<setw(10)<<Four.Reg2<<
setw(10)<<Four.Reg3<<setw(10)<<Four.Reg4<<setw(10)<<Four.total<<endl;
candInfo Winner;
Winner=One;
if(Two.total>Winner.total)
Winner=Two;
if(Three.total>Winner.total)
Winner=Three;
if(Four.total>Winner.total)
Winner=Four;
if(Five.total>Winner.total)
Winner=Five;
if(Six.total>Six.total)
Winner=Six;
cout << "Winner: "<<Winner.lastName<< " "<<Winner.firstName<<" "<<
"Votes Received: "<<Winner.total<<endl;
int totalVotes=One.total+Two.total+Three.total+Four.total+Five.total+Six.total;
cout<< "Total Votes Accounted For: "<<totalVotes<<endl;
return 0;
}