C++ do while loop Asks user for selection and returns that selection

Description

C++ do while loop Asks user for selection and returns that selection

#include <iostream>
using namespace std;
#include <stdlib.h>
int main()/*w w w.j a v  a  2 s.c om*/
{
   int ans;
   do
   {
      cout << "Do you want to:\n\n";
      cout << "\t1. Run the word processor \n\n";
      cout << "\t2. Run the database program \n\n";
      cout << "What is your selection? ";
      cin >> ans;
   } while ((ans != 1) && (ans != 2));  // Ensures user enters 1 or 2.
   exit(ans);  // Return value to operating system.
   return 0;   // Return does not ever execute due to exit().
}



PreviousNext

Related