+ 1
Pls help... I dont need complete solution.....the code only changes letters 'a' to 'f'...pls someone tell me what went wrong
#include <iostream> using namespace std; int main() { string word; int excess; getline(cin, word); int len = word.length(); // for loop changes all the letters to lower case for(int i = 0; i < len; i++){ if(word[i] == 32){ continue; } else if(word[i] < 97){ word[i] = word[i] + 32; } } for(int i = 0; i < len; i++){ if(word[i] == 32){ continue ; } word[i] = word[i] + 25; if(word[i] > 122){ excess = word[i] - 122; word[i] = 122; word[i] = word[i] - excess ; } } cout << word; return 0; }
5 Antworten
+ 2
Oluwatowo Rosanwo
I fixed your code as it was.
Further optimization can be done.
If you have questions feel free to ask.
https://code.sololearn.com/cSAm4ZGh7Ng3/?ref=app
+ 2
Ooh Yeeah. ...i thought as much, i didn't realise ASCII had a limit,
I guess yours was much better after all. ..😂😂
Thanks a lot Pro ✊👌, i get it now
0
Oluwatowo Rosanwo Is it ok?
0
It was perfect Mihai Apostol ...thanks a lot
Although i still don't understand how it works.. 😂😂
I was so sure mine would work, buh i don't know what went wrong
0
Oluwatowo Rosanwo
In my fix, to revert one lower case letter:
word[i] = 97 + 122 - word[i] = 219 - word[i]
i.e. to 'a' add 'z' - letter.
Your idea was good but you were going out of ASCII range which is upto 126. Check below code:
https://code.sololearn.com/c7kz2s67cDAp/?ref=app