I am trying to read a file named elect12.csv elect12.csv sample in Excel and get the values in the last column (state) and compare it with a user inputted variable (stateCode). However, every time I run my program I am unable to prompt the user to reinput the value. How can I get this working? Thanks.
//Read popular votes file ifstream pVotesFile ("elect12.csv");
for (int i = 0; i < statecount; i++)
{
if(pVotesFile.is_open())
{
cout << "Enter state code: ";
cin >> stateCode;
while (pVotesFile >> obama >> romney >> other >> total >> state)
{
if (stateCode == state)
{
statePoints = ((double)(obama - romney) / total) * 100;
stateTotal += statePoints;
}
else
{
cout << "Enter state code: ";
cin >> stateCode;
stateTotal = 0;
}
}
}
If the picture happens to go down sometime in the future, here is what the first few lines of the file look like:
"795696 1255925 22717 2074338 AL"
"122640 164676 13179 300495 AK"
"1025232 1233654 40368 2299254 AZ"
"394409 647744 27315 1069468 AR"
"7854285 4839958 344304 13038547 CA"