frostblooded

Untitled

Jan 10th, 2018
209
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.64 KB | None | 0 0
  1. bool input_is_valid(char str[WANTED_STRING_LENGTH + 1]) {
  2.     if(string_length(str) > WANTED_STRING_LENGTH) {
  3.         return false;
  4.     }
  5.  
  6.     for(int i = 0; str[i] != '\0'; i++) {
  7.         if(str[i] < 'a' || str[i] > 'z') {
  8.             return false;
  9.         }
  10.     }
  11.  
  12.     return true;
  13. }
  14.  
  15. int main() {
  16.     char str[WANTED_STRING_LENGTH + 1];
  17.  
  18.     do{
  19.         cout << "Enter a string up to " << WANTED_STRING_LENGTH << " characters long"
  20.              << " and composed only of small letters from the english alphabet:" << endl;
  21.         cin.getline(str, WANTED_STRING_LENGTH + 2);
  22.     } while(!input_is_valid(str));
  23.    
  24.     return 0;
  25. }
Advertisement
Add Comment
Please, Sign In to add comment