I'm working on a program where I need to input a file with 5 candidates names and votes, and output the name, votes, and the percentage of total votes that candidate received, as well as the overall winner. Right now I've been able to create some arrays and output the basic information, but I have two problems:
1). My output is showing
-858993460
Johnson 5000
Miller 4000
Duffy 6000
Robinson 2500
Ashtony 1800
Press any key to continue . . .
But, I don't know where the -858993460 is coming from...!?!
2). Where should I go from here?
Here is my code:
#include <iostream>
#include <iomanip>
#include <string>
#include <fstream>
using namespace std;
void main()
{
int numCan = 0;
string candidates[10];
int votes[10];
ifstream inFile;
inFile.open("candidates.txt");
while(inFile && numCan < 10)
{
cout << candidates[numCan] << " " << votes[numCan] << endl;
numCan++;
inFile >> candidates[numCan] >> votes[numCan];
}
inFile >> candidates[numCan] >> votes[numCan];
inFile.close();
}