Question: I need to write a C++ program that can read a team roster from a .csv file and count how many players are NOT from

I need to write a C++ program that can read a team roster from a .csv file and count how many players are NOT from a certain state.

This is what I have but it doesnt work. There is a second part that asks to count all the E's in the file but that part I have working.

#include

#include

#include

#include

#include

using namespace std;

players()

{

char count[256]={0};

string line;

char next, ch;

int A,L;

int counter=0;

ifstream inFile;

inFile.open("roster.csv");

if (inFile.fail())

{

cout<<" The file was not successfully opened"<

exit(1);

}

while (!inFile.eof())//while loop to count letters from opened file

{

inFile.get(next);//grabs lines from file to count

if (ch!="A")counter++;

if (ch!="L")counter++;

}

}

int main()

{

int counter=0;

int letterCount[26]={0};//initializes alphabet to be counted

string filename;//declares string

char next , ch;//declares character names

int e=0;// character to be counted

ifstream inFile;//allows files to be read

inFile.open("roster.csv");//opens comma delimited file

if (inFile.fail())//enables default fail message

{

cout<<" The file was not successfully opened"<

exit(1);//tells program to quit on fail

}

while (!inFile.eof())//while loop to count letters from opened file

{

inFile.get(next);//grabs lines from file to count

if (next=='e')e++;//counts the e's in the lines

}

cout<<"E appears "<

players();

cout<<"There are "<

return 0;

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!