Checking if IX or IV are followed by another character
<p>I have an algorithm that is supposed to take a string called <code>str</code> and check it against a specific rule defined as:</p>

<p>NOTHING comes after IX or IV.
It will print legal if the rule is not broken, and Illegal if the rule IS broken.</p>

<p>Here is my code that I have created:</p>

<pre><code>string str = "MXCIVXX";
int length = str.length();
bool legal = true;
for (int i = 0; i &lt; length; i++) {
    if ((str[i] == 'I' &amp;&amp; str[i + 1] == 'X') &amp;&amp; (str[i + 2] != '/0'))
        legal = false;

    if ((str[i] == 'I' &amp;&amp; str[i + 1] == 'V') &amp;&amp; (str[i + 2] != '/0'))
        legal = false;
}
if (legal == true)
    cout &lt;&lt; "Legal" &lt;&lt; endl;
else if (legal == false)
    cout &lt;&lt; "Illegal" &lt;&lt; endl;
</code></pre>

<p>I have tested multiple roman numerals in the string but it prints out legal if IX is followed by another character in the string. How can I fix this to confirm that IX or IV is not followed by another character?</p>