title: How do you add certain values in map based off of user input?
body: <p>I'm trying to make a <a href="https://en.wikipedia.org/wiki/Gematria" rel="nofollow noreferrer">Gematria</a> calculator in c++ and want to get the same results i am getting in java. How would I get so in C++ it could print the sum of the values from what the user inputs and get the same ultimate result as I would in Java? Please note I'm a beginner at C++ so please forgive me for any ignorance in this question.</p>
  <p>I managed <a href="https://stackoverflow.com/questions/62987856/how-do-you-add-up-certain-values-in-hashtable-based-off-of-user-input">thanks to stackoverflow</a> to make one in Java. In Java I have I could enter multiple words and get the Gematria, and I want to get the same results in C++.</p>
  <p><strong>Java Code</strong></p>
  <pre><code>package com.company;
  `import java.util.Hashtable;`
  `import java.util.Scanner;`
  
  public class English_Gematria {
     public static void main(String[] args) {
       Hashtable&lt;String, Integer&gt; Gematria_Values = new Hashtable&lt;&gt;();
       Gematria_Values.put(&quot; &quot;, 0);
       Gematria_Values.put(&quot;A&quot;, 1);
       Gematria_Values.put(&quot;B&quot;, 2);
       Gematria_Values.put(&quot;C&quot;, 3);
  // Goes through rest of alphabet.
  System.out.println(&quot;What do you want the gematria of?&quot;);
  Scanner i = new Scanner(System.in);
  String Gematria = i.nextline();
  int sum = 0;
  for (int j = 0; Gematria.length(); j++) {
      sum += Gematria_Values.get(String.valueOf(Gematria.toUpperCase().charAt(j)));
  }
  System.out.println(&quot;The Gematria of &quot; + Gematria + &quot; is &quot; + sum);
  </code></pre>
  <p><strong>C++ Code</strong></p>
  <pre><code>#include &lt;iostream&gt;
  #include &lt;cmath&gt;
  #include &lt;map&gt;
  
  using namespace std;
  
  int main() {
  std::map&lt;std::string, std::double_t&gt; Gematria_Values;
  Gematria_Values[&quot; &quot;] = 0;
  Gematria_Values[&quot;A&quot;] = 1;
  Gematria_Values[&quot;B&quot;] = 2;
  Gematria_Values[&quot;C&quot;] = 3;
  //  Goes through rest of alphabet.
  std::string Gematria;
  std::cout &lt;&lt; &quot;What do you want the gematria of?&quot; &lt;&lt; std::endl;
  std::cin &gt;&gt; Gematria;
  transform(Gematria.begin(), Gematria.end(), Gematria.begin(), ::toupper);
  int sum = 0;
  for (int i = 0; i &lt; Gematria.length(); i++)
  { 
  sum += Gematria_Values.at(Gematria);
  }
  std::cout &lt;&lt; &quot;The Gematria is &quot; &lt;&lt; sum;
  
  return 0;
  
  }
  </code></pre>
  <p>In C++ when user input is (without the quotes) &quot;a&quot; or &quot;A&quot; I get</p>
  <pre><code>The Gematria is 1.
  </code></pre>
  <p>When the user input is (without the quotes) &quot;b&quot; or &quot;B&quot; I get</p>
  <pre><code>The Gematria is 2.
  </code></pre>
  <p>However when the user input is (without the quotes) &quot;ab&quot; or &quot;bb&quot; I get</p>
  <pre><code>terminate called after throwing an instance of 'std::out_of_range'
    what():  map::at
  </code></pre>
  <p>My question is: How would I get the same the ultimate result as I do in Java?</p>