Advertisement
Guest User

Untitled

a guest
Feb 21st, 2019
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.35 KB | None | 0 0
  1. int menu_counter = 0;
  2.     cout << " ENTER THE BOOK ISBN:   ";
  3.     // Let the User enter in Book ISBN...
  4.     getline(cin, book_isbn);
  5.     //cout << "book length is:  " << book_isbn.length() << endl;
  6.     // Let's loop through the ISBN string to check if there are any normal letters instead of just numbers.
  7.     cout << "The string is " << book_isbn.empty() << endl;
  8.     for (int i = 0; menu_counter < book_isbn.size(); i++)
  9.     {
  10.         //cout << isdigit(book_isbn[menu_counter]) << endl;
  11.         int result_test = isdigit(book_isbn[menu_counter]); // The Result of the Position is a Digit or not
  12.         // If the Digit is 0, then that means we came across a letter, and the user must start over.
  13.         if (result_test == 0)
  14.         {
  15.             // Check to see if there is a dash somewhere...
  16.             if (book_isbn[menu_counter] == '-')
  17.             {
  18.                 menu_counter++; // Let's increase the menu counter to check more of the string...
  19.             }
  20.             // If there is no dash, then the user entered in something completely different
  21.             else
  22.             {
  23.                 //cout << endl;
  24.                 cout << "Please re-enter the ISBN Number:  ";
  25.                 getline(cin, book_isbn);
  26.             }
  27.         }
  28.         if (book_isbn.empty())
  29.         {
  30.             //cout << endl;
  31.         cout << "Please re-enter the ISBN Number:  ";
  32.             getline(cin, book_isbn);
  33.         }
  34.         if(result_test != 0 && book_isbn.empty() != 1)
  35.         {
  36.             menu_counter++; // Let's increase the menu counter to check more of the string...
  37.         }
  38.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement