// checkNonAscii4A.cpp
// Tests whether an entered C-string
// contains any non-ASCII characters.
// Uses a combination of sentinel-controlled
// and flag-controlled repetition.
// Uses a return statement 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;

   // Search for a non-ASCII character:
   int index = 0;
   while ( text[index] != '\0' )
   {
      if ( text[index] < 0 )  {
         cout << "Your string contains at least one "
                     << "non-ASCII character." << endl;
         return 0;
      }  // if

      index++;
   }  // while

   // If this point has been reached, the string
   // does not contain any non-ASCII characters.

   // Output result:
   cout << "Your string does not contain any "
                     << "non-ASCII characters." << endl;

   return 0;
}  // function main