/* cw1_example.cc Written 13/8/2003 by Chris Gillespie * * Description - Tries to predict if the user has guessed heads * or tails. The output follows the rules as stated * on http://www.comp.leeds.ac.uk/ai23/assessment/assessment1.html * Students should change the means of guessing. * * Notes - altering the I/O format in this wfile is not advised * if you wish to evaluate the program against the automated * system. */ #include using namespace std ; char dummy[70] ; // ignore this. int main() { int guess_number = 1 ; char user ; // what the user was thinking of char guess ; // what we think the next one will be do { // ask the user to think. cout << "Please think of Heads (H) or Tails (T) then press enter." << endl ; /* ************************************************************* ************************************************************* THIS IS THE BIT YOU SHOULD CHANGE!!!! We make our guess here. ************************************************************* ************************************************************* */ if ( guess_number == 1 ) { guess = 'H' ; } else { if ( user == 'H' ) { guess = 'H' ; } else { guess = 'T' ; } } /* ************************************************************ ************************************************************ DO NOT CHANGE ANYTHING AFTER HERE *********************************************************** *********************************************************** */ // now we tell the user what our guess was, cin.getline(dummy, 70) ; // wait for return key pressed cout << guess << endl ; // Find out what the user was thinking of // and force them to user H or T cin >> user ; cin.getline(dummy,70) ; // clear the stream for return key press while ( user != 'H' && user != 'T' ) { cerr << "You must enter H or T" << endl ; cin >> user ; cin.getline(dummy,70); // and again } guess_number++ ; } while ( guess_number <= 100 ) ; }