o

-
Last edited on
// Get the input for the first starting number and check if its positive

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
int getPositiveInput ()
{
   const int NUMBER_OF_ATTEMPTS = 3;
   int firstStartingNumber_p;
   int counter = 0;

   do
   {
      cout << "Please enter the first number for the program." << endl;
      cin >> firstStartingNumber_p;
   } while ( firstStartingNumber_p <= 0 && ++counter < NUMBER_OF_ATTEMPTS );

   if ( counter == NUMBER_OF_ATTEMPTS ) firstStartingNumber_p = 0;

   return firstStartingNumber_p;
}
 
Topic archived. No new replies allowed.