Advertisement
Guest User

Untitled

a guest
Mar 26th, 2019
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.78 KB | None | 0 0
  1. /* This function checks if the given string is a number */
  2. bool isnumber(const string& str)
  3. {
  4.     for(auto chr : str)
  5.         if(chr <= '0' && chr >= '9')
  6.             return false;
  7.     return true;
  8. }
  9.  
  10. /* Converts the given char to ascii */
  11. void convertToAscii()
  12. {
  13.     try {
  14.         const string& result = input("to_ascii>>>");
  15.         if(isnumber(result)) {
  16.             cout << "1";
  17.             int val = stoi(result);
  18.             if(val >= 1 && val <= 126)
  19.                 cout << (char)val << endl;
  20.             else
  21.                 throw "The value doesn't correspond to the {1, 126} range";
  22.         }
  23.         else
  24.             throw "The value must be of type int";
  25.     }
  26.     catch(const char* exp) {
  27.         cout << LINE + exp + LINE;
  28.         convertToAscii();
  29.     }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement