Asks user for his or her selection and returns that selection to the operating system with exit(). - C++ Function

C++ examples for Function:Useful Function

Description

Asks user for his or her selection and returns that selection to the operating system with exit().

Demo Code

#include <iostream>
using namespace std;
#include <stdlib.h>
int main()// w  w w  .j ava  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().
}

Result


Related Tutorials