Source of test_usersaysyes.cpp


  1: //test_usersaysyes.cpp
  2: //A test driver for the Scobey::userSaysYes() free function.
  3: //Illustrates how this function can be used to get
  4: //the user's response to a simple question with a 
  5: //yes-or-no answer.

  7: #include <iostream>
  8: using namespace std;

 10: #include "utilities.h"
 11: using Scobey::userSaysYes;
 12: using Scobey::Pause;

 14: int main()
 15: {
 16:     Pause(0, "\nTesting the Scobey::userSaysYes() free function ..."
 17:         "\n\nWe show the use of the Scobey::userSaysYes() free function "
 18:         "in an if statement,\nan if-else statement, a while loop, and a "
 19:         "do-while loop. In each case the idea\nis to determine what to "
 20:         "do based on the user's response to a yes-or-no type of\nquestion. "
 21:         "The if statement and the if-else statement are both repeated, so "
 22:         "you\nhave a chance to respond in both possible ways.");

 24:     Pause(0, "First the two if statements ... ");
 25:     if (userSaysYes("Would you like to do this?"))
 26:         cout << "OK, let's do this!\n";
 27:     if (userSaysYes("Would you like to do this?"))
 28:         cout << "OK, let's do this!\n";

 30:     Pause(0, "\nNext the two if-else statements ... ");
 31:     if (userSaysYes("Would you like to do that?"))
 32:         cout << "OK, let's do that!\n";
 33:     else
 34:         cout << "OK, let's not do that!\n";
 35:     if (userSaysYes("Would you like to do that?"))
 36:         cout << "OK, let's do that!\n";
 37:     else
 38:         cout << "OK, let's not do that!\n";

 40:     Pause(0, "\nNow the while loop ... ");
 41:     while (userSaysYes("Would you like to blah, blah ... ?"))
 42:     {
 43:         Pause(0, "OK, now we blah, blah ... ");
 44:     }
 45:     Pause(0, "And now we are beyond the blah, blah while loop.");

 47:     Pause(0, "\nFinally, the do-while loop ... ");
 48:     do
 49:     {
 50:         cout << "\nNow doing this other thing ...\n";
 51:     }
 52:     while (userSaysYes("Do these two things again?"));

 54:     Pause(0, "\nNo more tests to perform."
 55:         "\nProgram will now terminate.");
 56: }