// readInt2a.cc P. Conrad 02.08.06  for CISC181
// read an integer from the keyboard and print it out

// This version based on a suggestion from a student:
//  use an if test to check whether the first character
//  is Zero.  If it is not, and the returned value from
//  atoi IS zero, then we want to assume that the input
//  is invalid.

#include <iostream> // we are doing normal keyboard i/o 
using namespace std; // we'll talk about this later

int main(void)
{
  char buffer1[512]; // a nice big character buffer

  int x;  // you must declare variables before you use them

  // prompt the user for an integer
  cout << "Please enter an integer: ";

  cin.getline(buffer1,512);

  x = atoi(buffer1); // converts from ASCII to integer


  if ( buffer1[0] != '0' && x == 0  )
    cout << "Your input was invalid." << endl;
  else
   cout << "You entered " << x << endl;


  return 0;
}

