// RepeatableGame.cpp (c) Kari Laitinen // http://www.naturalprogramming.com/ // 2013-11-14 File created. // 2014-04-25 Last modification. // This is a repeatable version of the 'game' that is // presented in Game.cpp. #include #include using namespace std ; int main() { bool user_wants_to_play_more = true ; while ( user_wants_to_play_more == true ) { cout << "\n This program is a computer game. Please, type in " << "\n an integer in the range 1 ... 2147483646 : " ; char given_integer_as_string[] = "000000000000000000" ; cin.getline( given_integer_as_string, sizeof( given_integer_as_string ) ); int integer_from_keyboard = atoi( given_integer_as_string ) ; int one_larger_integer = integer_from_keyboard + 1 ; cout << "\n You typed in " << integer_from_keyboard << "." << "\n My number is " << one_larger_integer << "." << "\n Sorry, you lost. I won. The game is over. \n" ; cout << "\n You want to play more (Y/N) ? " ; char user_choice[] = "???" ; cin.getline( user_choice, sizeof( user_choice ) ) ; if ( strlen( user_choice ) == 0 ) { user_wants_to_play_more = false ; } else if ( user_choice[ 0 ] != 'Y' && user_choice[ 0 ] != 'y' ) { user_wants_to_play_more = false ; } } }