logical operators in if statements c++ : <p>The current code at the bottom works but I can't combine the if statements without shifting the ascii values to a position that I don't want them to be. The encryption is supposed to be only alphabet values. Capital and lowercase z's are supposed to loop around to an A. I have a teacher but she doesn't know so I would be grateful for any help. Thanks &lt;3</p>

<p>This doesn't work...</p>

<pre><code>if (sentence[i] == 'z' || 'Z')
{
sentence[i] = sentence[i] - 26;
}
</code></pre>

<p>And this doesn't work </p>

<pre><code>if (sentence[i] == 'z' || sentence[i] == 'Z')
{
sentence[i] = sentence[i] - 26;
}
</code></pre>

<p>This works.</p>

<pre><code>if (sentence[i] == 'z')
{
sentence[i] = sentence[i] - 26;
}
if (sentence[i] == 'Z')
{
sentence[i] = sentence[i] - 26;
}
</code></pre>

<p>Full code.  </p>

<pre><code>#include &lt;iostream&gt;
#include &lt;string&gt;

using namespace std;

class EncryptionClass
{
    string sentence;

public:

    //constructors
    EncryptionClass(string sentence)
        {setString(sentence);}
    EncryptionClass()
        {sentence = "";}

    //get and set
    string getString()
        {return sentence;}
    void setString(string sentence)
        {this-&gt; sentence = sentence;}

    //encrypt
    void encryptString()
    {
        for(int i = 0; i &lt; sentence.length(); i++)
        {
            if (isalpha(sentence[i]))
            {

                if (sentence[i] == 'z')
                {
                    sentence[i] = sentence[i] - 26;
                }
                if (sentence[i] == 'Z')
                {
                    sentence[i] = sentence[i] - 26;
                }

                sentence[i] = sentence[i] + 1;
            }
        }
    }
};

int main()
{
    string sentence;
    cout &lt;&lt; "Enter a sentence to be encrypted. ";
    getline(cin, sentence);
    cout &lt;&lt; endl;

    EncryptionClass sentence1(sentence);
    cout &lt;&lt; "Unencrypted sentence." &lt;&lt; endl;
    cout &lt;&lt; sentence1.getString() &lt;&lt; endl &lt;&lt; endl;
    sentence1.encryptString();
    cout &lt;&lt; "Encrypted sentence." &lt;&lt; endl;
    cout &lt;&lt; sentence1.getString() &lt;&lt; endl;


    cin.get();
    return 0;
}
</code></pre>
