-4

so I have to read in a file in C++ and I think I'm doing everything right but when i go to debug it only a black screen appears and when i exit the black screen at the bottom under outputs it says cannot find or open pdb file. Can anyone find what i'm doing wrong? I have both of the files open until the resource files. Here's my code:

include iostream,
include string,
include fstream,
using namespace std;
struct dataStruct {
    string playerId,
    lastName,
    firstName,
    division,
    team;
    double plateAppearances,
    atBats,
    singles,
    doubles,
    triples,
    homeRuns,
    sackFlys,
    walks,
    hitByPitch,
    battingAvg,
    onBasePercentage,
    slugginPercentage,
    hits,
    sacrifices,
    sacrificeFlys;
};
int main() {
    string playerId = "",
    lastName = "",
    firstName = "",
    division = "",
    team = "";
    double plateAppearances = 0,
    atBats = 0,
    singles = 0,
    doubles = 0,
    triples = 0,
    homeRuns = 0,
    sackFlys = 0,
    walks = 0,
    hitByPitch = 0,
    battingAvg = 0,
    onBasePercentage = 0,
    slugginPercentage = 0; {
        dataStruct playerStats[500];
        dataStruct newPlayerStats[500];
        int counter = 0;
        int otherCounter = 0;
        ifstream inFile;
        ifstream masterData("Master_Data.csv", ios:: in );
        ifstream newStats("2014_League_Stats.csv");
        if (masterData.is_open()) {
            while (!masterData.eof()) {
                getline(masterData, playerStats[counter].playerId, ',');
                getline(masterData, playerStats[counter].firstName, ',');
                getline(masterData, playerStats[counter].lastName, ',');
                getline(masterData, playerStats[counter].division, ',');
                getline(masterData, playerStats[counter].team, ',');
                masterData >> playerStats[counter].plateAppearances;
                masterData.ignore(',');
                masterData >> playerStats[counter].atBats;
                masterData.ignore(',');
                masterData >> playerStats[counter].singles;
                masterData.ignore(',');
                masterData >> playerStats[counter].doubles;
                masterData.ignore(',');
                masterData >> playerStats[counter].triples;
                masterData.ignore(',');
                masterData >> playerStats[counter].homeRuns;
                masterData.ignore(',');
                masterData >> playerStats[counter].sackFlys;
                masterData.ignore(',');
                masterData >> playerStats[counter].walks;
                masterData.ignore(',');
                masterData >> playerStats[counter].hitByPitch;
                masterData.ignore(',');
                masterData >> playerStats[counter].battingAvg;
                masterData.ignore(',');
                masterData >> playerStats[counter].onBasePercentage;
                masterData.ignore(',');
                masterData >> playerStats[counter].slugginPercentage;
                masterData.ignore(',');
            }
        } else {
            cout << "Error Reading File" << endl;
        }
        if (newStats.is_open()) {
            while (!newStats.eof()) {
                getline(newStats, newPlayerStats[otherCounter].playerId, ',');
                getline(newStats, newPlayerStats[otherCounter].firstName, ',');
                getline(newStats, newPlayerStats[otherCounter].lastName, ',');
                getline(newStats, newPlayerStats[otherCounter].division, ',');
                getline(newStats, newPlayerStats[otherCounter].team, ',');
                newStats >> newPlayerStats[otherCounter].plateAppearances;
                newStats.ignore(',');
                newStats >> newPlayerStats[otherCounter].atBats;
                newStats.ignore(',');
                newStats >> newPlayerStats[otherCounter].singles;
                newStats.ignore(',');
                newStats >> newPlayerStats[otherCounter].doubles;
                newStats.ignore(',');
                newStats >> newPlayerStats[otherCounter].triples;
                newStats.ignore(',');
                newStats >> newPlayerStats[otherCounter].homeRuns;
                newStats.ignore(',');
                newStats >> newPlayerStats[otherCounter].sackFlys;
                newStats.ignore(',');
                newStats >> newPlayerStats[otherCounter].walks;
                newStats.ignore(',');
                newStats >> newPlayerStats[otherCounter].hitByPitch;
                newStats.ignore(',');
                newStats >> newPlayerStats[otherCounter].battingAvg;
                newStats.ignore(',');
                newStats >> newPlayerStats[otherCounter].onBasePercentage;
                newStats.ignore(',');
                newStats >> newPlayerStats[otherCounter].slugginPercentage;
                newStats.ignore(',');
            }
        } else {
            cout << "Error Reading File" << endl;
        }
        if (inFile.is_open()) {
            while (!masterData.eof()) {
                playerStats[counter].atBats = (playerStats[counter].plateAppearances +
                    newPlayerStats[otherCounter].plateAppearances) -
                    ((playerStats[counter].walks + newPlayerStats[otherCounter].walks) +
                    (playerStats[counter].hitByPitch + newPlayerStats[otherCounter].hitByPitch) +
                    (playerStats[counter].sacrifices + newPlayerStats[otherCounter].sacrifices));
                playerStats[counter].hits = ((playerStats[counter].singles + newPlayerStats[otherCounter].singles) +
                    (playerStats[counter].doubles + newPlayerStats[counter].doubles) +
                    (playerStats[counter].triples + newPlayerStats[otherCounter].triples) +
                    (playerStats[counter].homeRuns + newPlayerStats[otherCounter].homeRuns));
                playerStats[counter].battingAvg = ((playerStats[counter].hits) / ((playerStats[counter].atBats)));
                playerStats[counter].onBasePercentage = ((playerStats[counter].hits) +
                    (playerStats[counter].hitByPitch) + newPlayerStats[otherCounter].hitByPitch) +
                    (playerStats[counter].walks + newPlayerStats[otherCounter].walks) /
                    ((playerStats[counter].atBats) + (playerStats[counter].walks + newPlayerStats[otherCounter].walks) +
                    (playerStats[counter].hitByPitch) + newPlayerStats[otherCounter].hitByPitch) +
                    (playerStats[counter].sacrificeFlys);
                playerStats[counter].slugginPercentage = (playerStats[counter].hits / playerStats[counter].atBats);
                masterData.close();
                newStats.close();
            }
        }
    }
}
MrHug
  • 1,315
  • 10
  • 27
Kathy
  • 1
  • 1
    http://stackoverflow.com/questions/15937707/error-message-cannot-find-or-open-the-pdb-file – David G Nov 24 '14 at 20:30
  • Can you reformat your code so that it is legible for us to read? Also, the much needed question is - have you tried using your debugger to find where the problem occurs? – KillaBytes Nov 24 '14 at 20:36
  • @kozmik yeah when i click to debug it run through the program opens a black screen with nothing on it and then when i exit the black screen on the bottom it says that it cannot find or open the file – Kathy Nov 24 '14 at 21:49

1 Answers1

0

Okay lets start with the basics and move on from there. Since I don't have a copy of your .csv file I will make some assumptions when you are reading information in but most of these corrections pertain to how we read from the file in c++.

I understand most of these corrections will be just from editing your post but I take nothing for granted:

include iostream, // should be #include <iostream> - no comma.
include string,   // same here #include <string> - no comma.
include fstream,  // ditto.

Your brackets are also your main concern in order to even compile this code you are using brackets freely where they don't or shouldn't belong. Just get rid of the extra brackets and you will be fine.

int main() {
string playerId = "",
lastName = "",
firstName = "",
division = "",
team = "";
double plateAppearances = 0,
atBats = 0,
singles = 0,
doubles = 0,
triples = 0,
homeRuns = 0,
sackFlys = 0,
walks = 0,
hitByPitch = 0,
battingAvg = 0,
onBasePercentage = 0,
slugginPercentage = 0; { // Why is this here?
    dataStruct playerStats[500];
    dataStruct newPlayerStats[500];

Lets look at how you would read from a file:

if (inFile.is_open()) {
        while (!masterData.eof()) {
            playerStats[counter].atBats = (playerStats[counter].plateAppearances +
                newPlayerStats[otherCounter].plateAppearances) -
                ((playerStats[counter].walks + newPlayerStats[otherCounter].walks) +
                (playerStats[counter].hitByPitch + newPlayerStats[otherCounter].hitByPitch) +
                (playerStats[counter].sacrifices + newPlayerStats[otherCounter].sacrifices));
            playerStats[counter].hits = ((playerStats[counter].singles + newPlayerStats[otherCounter].singles) +
                (playerStats[counter].doubles + newPlayerStats[counter].doubles) +
                (playerStats[counter].triples + newPlayerStats[otherCounter].triples) +
                (playerStats[counter].homeRuns + newPlayerStats[otherCounter].homeRuns));
            playerStats[counter].battingAvg = ((playerStats[counter].hits) / ((playerStats[counter].atBats)));
            playerStats[counter].onBasePercentage = ((playerStats[counter].hits) +
                (playerStats[counter].hitByPitch) + newPlayerStats[otherCounter].hitByPitch) +
                (playerStats[counter].walks + newPlayerStats[otherCounter].walks) /
                ((playerStats[counter].atBats) + (playerStats[counter].walks + newPlayerStats[otherCounter].walks) +
                (playerStats[counter].hitByPitch) + newPlayerStats[otherCounter].hitByPitch) +
                (playerStats[counter].sacrificeFlys);
            playerStats[counter].slugginPercentage = (playerStats[counter].hits / playerStats[counter].atBats);
            masterData.close(); // You close the file in your while loop
            newStats.close(); // You close the file in your while loop
        }
    }

You close both files in your while loop when you are collecting information. So lets say masterdata has information you want to read from before the end of the file - you close it after you complete the first sequence of information gathering inside your while loop. Take the code masterData.close(); AND newStats.close(); out of your while loop and if statements and place it right before you exit main.

This leads me to my other comment - Main should return something on successful completion of the program. (i.e. return 0; OR return EXIT_SUCCESS;).

KillaBytes
  • 447
  • 3
  • 10