title: Mapping numerical values to characters
body: <p>Using C++, I am attempting to write a program that encrypts a string. I have to map each letter of the alphabet to a numerical value: for example, a = 0, b = 1, c = 2 and so on. So far, I have created a void function that takes a string as a parameter and uses a switch statement to output the values. The problem is, the values are chars, not ints and I can't use the math operators to alter them. 
  My source code is below:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;cstdlib&gt;
  #include &lt;ctime&gt;
  #include &lt;cstring&gt;
  #include &lt;string&gt;
  #include &lt;cctype&gt;
  
  using namespace std;
  
  void mapped_string(string in)
  {   string mapped_string;
      int length = in.length();
  
      for (int i = 0; i &lt; length; i++)
      {   
          switch (in[i])
          {
          case 'a':
              cout&lt;&lt;"0";
              break;
          case 'b':
              cout&lt;&lt;"1";
              break;
          case 'c':
              cout&lt;&lt;"2";
              break;
          case 'd':
              cout&lt;&lt;"3";
              break;
          case 'e':
              cout&lt;&lt;"4";
              break;
          case 'f':
              cout&lt;&lt;"5";
              break;
          case 'g':
              cout&lt;&lt;"6";
              break;
          case 'h':
              cout&lt;&lt;"7";
              break;
          case 'i':
              cout&lt;&lt;"8";
              break;
          case 'j':
              cout&lt;&lt;"9";
              break;
          case 'k':
              cout&lt;&lt;"10";
              break;
          case 'l':
              cout&lt;&lt;"11";
              break;
          case 'm':
              cout&lt;&lt;"12";
              break;
          case 'n':
              cout&lt;&lt;"13";
              break;
          case 'o':
              cout&lt;&lt;"14";
              break;
          case 'p':
              cout&lt;&lt;"15";
              break;
          case 'q':
              cout&lt;&lt;"16";
              break;
          case 'r':
              cout&lt;&lt;"17";
              break;
          case 's':
              cout&lt;&lt;"18";
              break;
          case 't':
              cout&lt;&lt;"19";
              break;
  
          default:
              cout&lt;&lt; in[i];
          }
      }
  }
  
  int main()
  {   string str1 = "Hello";
  
      mapped_string(str1);
  
  
  
          cout    &lt;&lt; "Press any key to exit." &lt;&lt; endl;
          cin.ignore(2);
          return 0;
  }
  </code></pre>
  
  <p>I need this function to map each char in the string to a int value and store the int values in a new string called mapped_string.</p>