I am working on some college work and having an issue with my assignment. The problem I am having is that my program won't open the txt file. I've read though my book and some of the documents on the website and seeing that much of what i have on my program almost matches. I know you're not suppose to help with homework but a pointer down the road or some tips/hints of whats the problem would be great. Here is my code currently.
//Christopher J. Lacour//
//Voting Array//
//Feb 07, 2013//
#include <iostream> //Declarations//
#include <string>
#include <fstream>
#include <iomanip>
double percentage(int val1, int val2); //setting the function to gain percentages//
usingnamespace std;
int main()
{
string candidate[100];
int vote[100]; //declaring variables for the program//
int numCandidate = 0, numVotes = 0, totalVotes = 0, candidateCounter = 0;
ifstream candidateList;
candidateList.open("candidateList.txt"); //opens the text file for the candidates//
if (candidateList.is_open())
{
while(candidateList.good())
{
getline(candidateList, candidate [candidateCounter]);
candidateCounter++;
}
}
for (int i = 1; i < numCandidate; i++)
{
cout << "Enter votes for " << candidate [i - 1]; //selects the candidate from the list//
cin >> numVotes; //user inputs the amount of votes for each candidate//
vote [i - 1] = numVotes;
totalVotes = totalVotes + numVotes;
}
candidateList.close();
double percentage(int val1, int val2); //calling function//
system("PAUSE");
return 0;
}
double percentage(int val1, int val2) //function calculates the percentage of the votes//
{
double perc =(val1/val2) * 100;
return perc;
}
If any more information is needed I'll gladly post, like I said, I'm not looking for a direct answer, just something that'll point me into the right path. Thanks for the help.