Pls help... I dont need complete solution.....the code only changes letters 'a' to 'f'...pls someone tell me what went wrong | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 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; }

24th Jan 2020, 4:27 PM
Oluwatowo Rosanwo
Oluwatowo Rosanwo - avatar
5 Answers
+ 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
24th Jan 2020, 9:55 PM
Mihai Apostol
Mihai Apostol - avatar
+ 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
26th Jan 2020, 3:43 PM
Oluwatowo Rosanwo
Oluwatowo Rosanwo - avatar
25th Jan 2020, 5:43 PM
Mihai Apostol
Mihai Apostol - avatar
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
26th Jan 2020, 6:38 AM
Oluwatowo Rosanwo
Oluwatowo Rosanwo - avatar
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
26th Jan 2020, 8:57 AM
Mihai Apostol
Mihai Apostol - avatar