// checkNonAscii2A.cpp
// Tests whether an entered C-string
// contains any non-ASCII characters.
// Uses a combination of sentinel-controlled
// and flag-controlled repetition.
// Uses a boolean variable to avoid
// continuing the search after a
// non-ASCII character has been found.

#include <iostream>
using namespace std;

int main()
{
   const int LENGTH = 15;

   // Announce purpose of program:
   cout << "Enter a string without white space, up to "
           << LENGTH << " characters.";
   cout << "This program will tell you whether it "
             << "contains any non-ASCII characters." << endl;

   // Ask user for a string, and echo it:
   cout << "Enter your string:> ";
   char text[LENGTH + 1];
   cin >> text;
   cout << "You typed: " << text << endl;

   // No non-ASCII character has been found YET:
   bool nonAsciiFound = false;

   // Search for a non-ASCII character:
   int index = 0;
   while ( text[index] != '\0' && !nonAsciiFound )
   {
      if ( text[index] < 0 )
         nonAsciiFound = true;
      index++;
   }  // while

   // Output result:
   cout << "Your string ";
   if ( nonAsciiFound )
      cout << "contains at least one non-ASCII character.";
   else
      cout << "does not contain any non-ASCII characters.";
   cout << endl;

   return 0;
}  // function main