Sinux1

PS8Q7.cpp

May 3rd, 2016
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.01 KB | None | 0 0
  1. #include <iostream>
  2. #include <cctype>
  3. using namespace std;
  4.  
  5. void validate(string numbs)
  6. {
  7.     if (!(numbs.length() == 11))
  8.         {
  9.         cout << "Problem: You must type exactly 11 characters.\n";
  10.         return;
  11.         }
  12.     else if (!(numbs.find_first_of('-') + 3 == numbs.find_last_of('-')))
  13.         {
  14.         cout << "Problem: The dashes are missing or are in the wrong spot\n";
  15.         return;
  16.         }
  17.     else
  18.         {
  19.         for (int sub = 0; sub < numbs.length();sub++)
  20.         {
  21.             if (sub == 3 || sub == 6)
  22.                 {
  23.                     continue;
  24.                 }
  25.             if (!(isdigit(numbs[sub])))
  26.                 {
  27.                     cout << "Problem: Only digits are allowed in a SSN\n";
  28.                     return;}
  29.                 }
  30.             cout << "That is valid.\n";
  31.  
  32.         }
  33.  
  34.  
  35. }
  36.  
  37.  
  38.  
  39. int main()
  40. {
  41.     string input;
  42.  
  43.     cout << "Enter your SSN in this format: XXX-XX-XXXX\n";
  44.     cin >> input;
  45.  
  46. validate(input);
  47.  
  48.  
  49.     return 0;
  50. }
Add Comment
Please, Sign In to add comment