/* * @topic Q00720 2/27/2014 the LOGICAL NOT (!) operator * @brief demonstrates that result of the ! operator is zero or one */ #include <iostream> void pause() { //---------------------------------------------- // prevent window from closing before exiting: //---------------------------------------------- char ch; // ch is a variable that holds a character // curious \n is a "line feed" control character, // it moves the cursor to the next line: std::cout << "\nEnter X to Exit: "; std::cin.ignore( 1, '\n' ); // extract and discard characters std::cin.clear(); // this clears cin state std::cin.get( ch ); // this reads a character from the keyboard, // and pauses the program from before exiting } int main() { for (;;) { int tmp; std::cout << "Enter a number or 5 to exit: "; std::cin >> tmp; if ( tmp == 5 ) { break; } if ( !tmp ) { std::cout << "!tmp == " << !tmp << '\n'; } else { std::cout << "!tmp == " << !tmp << '\n'; } } pause(); return 0; }