Question: I need help with C++ code can you fix my code? Here is my code #include #include #include using namespace std; // Function Declarations bool
I need help with C++ code
can you fix my code?
Here is my code
#include
// Function Declarations bool checkValidFileName(string filename); int main() { //Declaring variables string number,outfile1="",outfile2="";
//defines an input stream for the data file ifstream dataIn;
//Defines an output stream for the data file ofstream dataOut1,dataOut2;
string filename;
/* This loop will continue to iterate until * the user enters a filename that ends with txt */ while(true) { //Getting the filename entered by the user cout>filename;
//calling the function bool b=checkValidFileName(filename); if(b) { break; } else { cout
//Opening the input file dataIn.open(filename.c_str()); //checking whether the file name is valid or not if(dataIn.fail()) { cout
int pos=filename.find("."); string fname=filename.substr(0,pos); //Making the output filenames outfile1=fname+"-even.txt"; outfile2=fname+"-odd.txt";
//creating and Opening the output file dataOut1.open(outfile1.c_str()); //creating and Opening the output file dataOut2.open(outfile2.c_str());
//Writing the data to the output file while(dataIn>>number) { if(number.length()%2==0) { dataOut1
//Closing the intput file dataIn.close();
//Closing the output file. dataOut1.close(); //Closing the output file. dataOut2.close();
}
return 0; } /* This function will check whether * the input file ends with txt or not */ bool checkValidFileName(string filename) { int pos=filename.find("."); string str=filename.substr(pos+1,filename.length()); if(str.compare("txt")==0) return true; else return false; }
and here is an issue

2: Words 1 Summary Output differs. See highlights below. Special character legend Input words-1.txt Your output Enter the name of the input file: Expected output Enter the name of the input file: 20 words read in from words-1.txt 11 words written to words-1-even.txt 9 words written to words-1-odd.txt. 5: Words 2 Summary A Output differs. See highlights below. Special character legend Input words-2.txt Your output Enter the name of the input file: Expected output Enter the name of the input file: 16 words read in from words-2.txt 5 words written to words-2-even.txt- 11 words written to words-2-odd txt- 8: Words 3 Summary Output differs. See highlights below. Special character legend Input words-3.txt Your output Enter the name of the input file: Expected output Enter the name of the input file: 17 words read in from words-3.txte 10 words written to words-3-even.txt 7 words written to words-3-odd.txt
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
