Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cctype>
- using namespace std;
- void validate(string numbs)
- {
- if (!(numbs.length() == 11))
- {
- cout << "Problem: You must type exactly 11 characters.\n";
- return;
- }
- else if (!(numbs.find_first_of('-') + 3 == numbs.find_last_of('-')))
- {
- cout << "Problem: The dashes are missing or are in the wrong spot\n";
- return;
- }
- else
- {
- for (int sub = 0; sub < numbs.length();sub++)
- {
- if (sub == 3 || sub == 6)
- {
- continue;
- }
- if (!(isdigit(numbs[sub])))
- {
- cout << "Problem: Only digits are allowed in a SSN\n";
- return;}
- }
- cout << "That is valid.\n";
- }
- }
- int main()
- {
- string input;
- cout << "Enter your SSN in this format: XXX-XX-XXXX\n";
- cin >> input;
- validate(input);
- return 0;
- }
Add Comment
Please, Sign In to add comment