"c++ give options" Code Answer's

You're definitely familiar with the best coding language C++ that developers use to develop their projects and they get all their queries like "c++ give options" answered properly. Developers are finding an appropriate answer about c++ give options related to the C++ coding language. By visiting this online portal developers get answers concerning C++ codes question like c++ give options. Enter your desired code related query in the search bar and get every piece of information about C++ code related question on c++ give options. 

c++ give options

By Jakes_Bakes_CodeJakes_Bakes_Code on Jun 02, 2020
#include <iostream>
#include <iomanip>
using namespace std;

int IntegerOptionsBox(int NumberOfOptions, ...)
{
   //set the border options
   char sczCorners = '+';
   char sczVerticalFillers = '|';
   char sczHorizontalFillers = '-';
   char sczGeneralFillers = ' ';

   // set the spacing options
   int iLineWidth = 40;
   int iOptionSpace = 15;
   int iNumberSpace = 3;
   int iTabSpace = 3;

   int iRightSpace = iLineWidth - iOptionSpace - iNumberSpace - iTabSpace - 1;

   int counter = 0;

   do
   {
      counter++;

      va_list arguments; // A place to store the list of arguments

      va_start(arguments, NumberOfOptions); // Initializing arguments to store all values after NumberOfOptions

      //Top line of the output
      cout << sczCorners << setw(iLineWidth) << setfill(sczHorizontalFillers) << ""
           << sczCorners << "\n";

      //Main Lines of the output
      for (int i = 1; i <= NumberOfOptions; i++)
      {
         cout << sczVerticalFillers;
         cout << setw(iNumberSpace) << setfill(sczGeneralFillers) << right << i << ".";
         cout << setw(iTabSpace) << setfill(sczGeneralFillers) << left << "";
         cout << setw(iOptionSpace) << setfill(sczGeneralFillers) << left << va_arg(arguments, char *);
         cout << setw(iRightSpace) << setfill(sczGeneralFillers) << left << "" << sczVerticalFillers << "\n";
      }

      //Bottom line of the output
      cout << sczCorners << setw(iLineWidth) << setfill(sczHorizontalFillers) << "" << sczCorners << "\n";

      va_end(arguments); // Cleans up the list

      // User's selection process
      int iSelected;
      cout << "\nSelect one of the above options: ";
      cin >> iSelected;
      bool bInputValidated = cin.good(); // Tells if the input is a valid integer or not
      cin.clear();
      cin.ignore(99999, '\n');
      cout << "bInputValidated: " << bInputValidated << endl;
      int iOptionSelected;

      /////////////////////////////
      //      VALIDATION         //
      /////////////////////////////

      if ((bInputValidated == 1)) // if the input is a valid integer
      {
         if ((iSelected <= NumberOfOptions) && (0 < iSelected)) // if the integer is within the range of options
         {
            return iSelected;
         }
         else
         {
            cout << "The option you selected - " << iSelected << " - is not within the range of options. The options range from 1 to " << NumberOfOptions << ". Please try again.\n\n";
         }
      }
      else // the input is not a valid integer
      {
         cout << "The option you selected is not an integer (int) data type. Please try again." << counter << endl
              << endl;
      }

   } while (1);
}




int main() {
  int iOptionSelected = IntegerOptionsBox(2, "Option1", "Option2");

   switch (iOptionSelected)
   {
      case 1:
         cout << "You selected option 1\n";
         break;
   
      case 2:
         cout << "You selected option 2\n";
         break;

      default:
         cout << "This option shouldn't be possible\n";
         break;
   }

}

Add Comment

0

All those coders who are working on the C++ based application and are stuck on c++ give options can get a collection of related answers to their query. Programmers need to enter their query on c++ give options related to C++ code and they'll get their ambiguities clear immediately. On our webpage, there are tutorials about c++ give options for the programmers working on C++ code while coding their module. Coders are also allowed to rectify already present answers of c++ give options while working on the C++ language code. Developers can add up suggestions if they deem fit any other answer relating to "c++ give options". Visit this developer's friendly online web community, CodeProZone, and get your queries like c++ give options resolved professionally and stay updated to the latest C++ updates. 

C++ answers related to "c++ give options"

View All C++ queries

C++ queries related to "c++ give options"

Browse Other Code Languages

CodeProZone