• + 24 comments

    I would encourage the use of the modulus operator (%) over subtracting 26 because any input that is greater than 26 would break a program using subtraction.

        int rot;
        char a;
        string s;
        cin >> rot;
        cin >> s;
        cin >> rot;
        for(auto &c: s){
            if(isalpha(c)){
                a = isupper(c)?'A':'a';
                c= a + (c - a + rot)%26;
            }
        }       
        cout << s << endl;