-1

I am attempting to prompt for, and read, one file after another. The following code does not wait for the second file name to be entered and I'm not sure why.

do
  {
        cout << "Please enter a filename: ";
        getline(cin, fileName);

        fileStream.open(fileName);

        if (fileStream.fail())
          cout << "File Not Found!" << endl;        
        while (fileStream.get(ch))
        {
          ch = convertToLowerCase(ch);
          index = ch - 'a';
          counter[index]++;
        }

        for (int i = 0; i < 26; i++)
        {
            cout << char(i + 'a') << " occurs " << setw(5) << counter[i] << " times." << endl;
        }
     
      cout << "Would you like to read another file: ";
      cin >> ans;
  }  while (ans != 'q' || ans != 'Q');

Ideally, it would process one file, then prompt for another, process it, prompt, etc. until the user chose to quit.

CaitlinG
  • 1,955
  • 3
  • 25
  • 35

1 Answers1

0

The line while (ans != 'q' || ans != 'Q'); will always evaluate to true, regardless of the char value. Even if ans = 'q', ans != 'Q', so the expression evaluates to true.

Change the line to:

while (ans != 'q' && ans != 'Q');
firsttry
  • 84
  • 4