hi for my assignment i have to make a program that will read grades from a file called grade.txt and counts the number of each letter grade. I did my code and it compiles without no error but when I prompt the use for the file name, the dos window closes.can someone please help me here is my code.
#include<iostream>
#include<fstream>
using namespace std;
#include<cmath>
#include<string>
int main(void)
{
char grade;
int aCount=0,bCount=0,cCount=0,dCount=0,fCount = 0;
string filename; //declare variable filename to be a string(string is a char array)
cout<<"please enter file name to read from--->";
cin>>filename;//read file name into variable
ifstream infile; //set up pointer variable called infile
infile.open(filename.c_str()); //use function c_str() to convert value of variable filename so that .open
ofstream outfile;
outfile.open("output.txt");
while(infile>>grade){
switch(grade)
{
case 'A': case 'a': ++aCount;
break;
cout<<"the total for letter a is"<<aCount<<endl;
case 'B': case 'b': ++bCount;
break;
cout<<"the total for letter b is"<<bCount<<endl;
case 'C': case 'c': ++cCount;
break;
cout<<"the total for letter c is"<<cCount<<endl;
case 'D': case 'd': ++dCount;
break;
cout<<"the total for letter d is"<<dCount<<endl;
case 'F': case 'f': ++fCount;
break;
cout<<"the total for letter f is"<<fCount<<endl;