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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started