#include <iostream>
#include <fstream>
#include <string>
usingnamespace std;
int main ()
{
int count,limit,counter =0;
char exit_prog;
string word,number,filename,num;
ifstream reading;
cout << "Enter a number between 1 to 100" << endl;
cin >> limit;
while (limit <= 1 || limit >=100 )
{
cout << "Error" << endl;
cout << "Enter a number between 1 to 100" << endl;
cin >> limit;
count ++;
if ( count == 5)
{
cout << "You have so many try do you want to exit the program?" << endl;
cout << "Y for and N for No" << endl;
cin >> exit_prog;
if (exit_prog == 'Y' || exit_prog == 'y')
{
cout << "Thank you for using the program"<< endl;
EXIT_FAILURE;
break;
}
}
}
cout << "What is the filename that you want to open" << endl;
cin >> filename;
reading.open(filename.c_str());
if(reading)
{
reading >> word;
while (reading >> number)
{
if (number == limit)
counter += 1;
}
cout <<"The file contains the word " << word << " and the number " << limit << " appears " << counter << " times" << endl;
}
else
{
cout << "could not open the files." << endl;
}
reading.close();
}
What is the behavior of the program right now, and why is that behavior undesirable?
Can you show the contents of the file you're trying to pass to it?