c++ - How can i select A-Z without having typing an expression for every letter? -


this question has answer here:

i have while statement here says if user input z show corresponding telephone digit, else if enter letters a-z program exit. how can set expression a-z instead of typing multiple || statement every letter. know there library lets select a-z forgot name.

p.s want enable user select uppercase of these letter , still result.

sorry bad formatting of while. should scroll left , right see complete

         while (letter == 'a' || letter == 'b' || letter == 'c' || letter == 'd' ||                  letter == 'e' || letter == 'f' || letter == 'g' || letter == 'h' ||                  letter == 'i' ||  letter == 'j' || letter == 'k' || letter == 'l' ||   letter == 'm' ||                  letter == 'n' || letter == 'o' || letter == 'p' || letter == 'q' || letter ==                  'r' || letter == 's' || letter == 't' || letter == 'u' || letter == 'v' ||                  letter == 'w' || letter == 'x' || letter == 'y' || letter == 'z' )                                                           {                                                  //line 14                                 cout << "letter: " << letter;                  //line 15                                 cout << ", corresponding telephone digit: ";   //line 16                          num = static_cast<int>(letter)                         - static_cast<int>('a');                  //line 17                          if (0 <= num && num < 26)                      //line 18                         {                                              //line 19                             digit = (num / 3) + 2;                     //line 20                              if (((num / 3 == 6 ) || (num / 3 == 7))    //line 21                                 && (num % 3 == 0))                   //line 22                                 digit = digit - 1;                     //line 23                              if (digit > 9)                             //line 24                                 digit = 9;                             //line 25                              cout << digit << endl;                     //line 26                         }                                              //line 27                         else                                           //line 28                             cout << "invalid input." << endl;          //line 29                          cout << "\nenter uppercase "                         << "letter find corresponding "                         << "telephone digit." << endl;            //line 30                         cout << "to stop program enter #."                         << endl;                                  //line 31 

use std::isalpha

#include <cctype>  //... while (std::isalpha(letter)) 

Comments

Popular posts from this blog

java - nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet Hibernate+SpringMVC -

sql - Postgresql tables exists, but getting "relation does not exist" when querying -

asp.net mvc - breakpoint on javascript in CSHTML? -