// higherLowerDemo.cc   Demo of how to ask user "higher or lower"
// P. Conrad, 2/23/2004


// Here is a demo of how to do the "asking" part for char data,
// and some hints about how to process the responses.

// There are some scraps of code that may be useful for lab02,
// but only scraps; you'll need to redesign the actual logic of the
// program.  For instance, I've hard coded the guesses; you should
// be using a variable so you can adjust the guess up or down inside
// a while loop.

#include <iostream> // for cout, cin
using std::cout;
using std::cin;

#include <iomanip> // for endl and flush
using std::endl;
using std::flush;

int main(void)
{
  // greet user

  cout << "Please think of a number between 1 and 500" << endl;
  cout << "When you have thought of it, enter y (for yes) and press return." 
       << endl;

  char response = 'n';
  while (response != 'y')
    {
      cout << "Have you thought of it yet? " << flush;
      cin >> response;
    }
  
  cout << "Good.  My first guess is 500.  Is the number higher or lower?" 
       << endl;

  cout << "Enter h for higher, l for lower, or c for correct guess?"
       << flush; 

  response = ' ';
  while (response != 'h' &&
	 response != 'l' &&
	 response != 'c')
    {
      cin >> response;
      if (response != 'h' &&
	  response != 'l' &&
	  response != 'c')
	cout << "You are supposed to enter h, l , or c.  Try again: " 
	     << flush;
    }

  // Process responses.  In real program, you would need to 
  // be using a variable instead of "hard coding" the next guess.
  // Also, this whole business of the next guess needs to be in 
  // some kind of loop that terminates when the user guesses the 
  // correct answer.  Finally, you need to keep track of the number
  // of incorrect guesses.

  if (response == 'h')
    cout << "My next guess is 750" << endl; 
  else if (response == 'l')
    cout << "My next guess is 250" << endl;
  else if (response == 'c')
    cout << "Awesome! I got it in 1 guess." << endl ;
  else // at this point, you should have h, l, or c becuase of earlier loop
    {
      cerr << "There is something wrong with this program."
	   << "Ask a programmer for help.";
	exit (-1);
    }
  
  cout << endl;
  cout << "Sorry, that's all I know how to do so far." << endl;

  cout << "When some CISC181 student does her or his homework," << endl
       << "I'll be able to continue playing!" << endl
       << "Bye bye for now." << endl;

  return (0);

}

