title: I'm having a problem with reading a string in an if statement
body: <p>I'm a beginner in C++ coding and I have a problem with an assignment question:</p>
  
  <blockquote>
    <p>Write a C++ program that prompts the user to enter two characters and displays the major and status represented in the characters. The first character indicates the major and the second is number character 1, 2, 3, 4, which indicates whether a student is a freshman, sophomore, junior, or senior.
    Suppose the following characters are used to denote the majors:<br>
    M: Mathematics<br>
    C: Computer Science<br>
    I: Information Technology</p>
  </blockquote>
  
  <p>This is what I tried so far:</p>
  
  <pre class="lang-cpp prettyprint-override"><code>#include &lt;iostream&gt;
  #include &lt;string&gt;
  using namespace std;
  
  int main()
  {
      string i;
      cout &lt;&lt;"Enter two characters: ";
      cin&gt;&gt; i;
      i[0]=toupper(i[0]);
      if (i[0]=='M')
      {
          if (i[1]==1)
          {
              cout&lt;&lt;"Mathematics Freshman."&lt;&lt;endl;
          }
          else if (i[1]==2)
          {
              cout&lt;&lt;"Mathematics Sophomore."&lt;&lt;endl;
          }
          else if (i[1]==3)
          {
              cout&lt;&lt;"Mathematics Junior."&lt;&lt;endl;
          }
          else if (i[1]==4)
          {
              cout&lt;&lt;"Mathematics Senior."&lt;&lt;endl;
          }
          else
          {
              cout&lt;&lt;"Invalid status code."&lt;&lt;endl;
          }
      }
      return 0;
  }
  </code></pre>
  
  <p>When I run and type for example <code>"m1"</code> it should print <code>"Mathematics Freshman."</code>, but it prints <code>"invalid status code"</code>, which is the output from the <code>else</code> statement, and I don't know why. </p>