Strings-odd even character1

Take as input S, a string. Write a function that replaces every odd character with the character having just higher ascii code and every even character with the character having just lower ascii code. Print the value returned.

i got wrong answer …can anyone explain

https://ide.codingblocks.com/#/s/27885

Question says replace it with the character with just higher ascii value or just lower ascii value, and not highest or lowest character.

https://ide.codingblocks.com/s/34641

This is my code for this problem. Try submitting it, and comment below if you have any doubts.

1 Like

can u send the code again for the above pblm


indent preformatted text by 4 spaces
#include

#include

using namespace std;

int main() {

string s;

cin>>s;

int r=0;

for(int i=0;i<s.length();i++){

    int y=s[i];

    // cout<<s[i]<<" "<<y<<endl;

    if(i%2!=0){

        char x=s[i];

        x--;

        s[i]=x;

    }

    else{

        char x=s[i];

        x++;

        s[i]=x;

    }

}

cout<<s;



return 0;

}
indent preformatted text by 4 spaces