0

Bug in The Spy Life code coach

Can you say why the code below dont work in c++ ? In case of x[i] ==' '; It can not realize white spaces while In case of x[i] != ' '; it realize white spaces for(int i = x.length()-1; i >= 0; i--) { if ((x[i] >= 'a' && x[i] <= 'z') || x[i] == ' ' ) { y[i] = x[i]; } cout << y[i]; }

10th May 2023, 7:24 PM
Code Angel
Code Angel - avatar
4 ответов
+ 4
sololearn advice: you'll get better help if you a) save your work as a code bit and link directly, and b) don't assume we know what a given code coach is, cause there are a lot of em; at least c/p the instructions as so: > Create a program that will take the encoded message, flip it around, remove any characters that are not a letter or a space, and output the hidden message. Code advice: This problem is much easier with regex, since C++ does handle it, but in the absence of that your solution should work in general except that you're not handling capital letters. But be warned that there are non-letter symbols between the upper and lowercase letters, so you can't just use A~z. As for the spaces, I don't really see any problems with the syntax, but double-check that you're using the correct normal space there and not one of the weird ones like nbsp. That can sneak through undetected indefinitely, so better to rule it out early , or eliminate the possibility entirely with something like char(20)
10th May 2023, 8:15 PM
Orin Cook
Orin Cook - avatar
+ 1
Oh ok, cin is the culprit: it stops reading at a white space. You'll want to use getline instead. Also, your inequality is backwards for Z
11th May 2023, 4:06 AM
Orin Cook
Orin Cook - avatar
0
First : Time is gold and you allocate some of your time to this problem so thank you very much. Here is the code : https://code.sololearn.com/cXY8OT4ikULR/?ref=app There is an if condition to detect the lower case and else if condition to detect the upper case and finally an else if to detect the white-spaces. The output is similar to test case#1 and test case #5 but for test case #2 output should be you are great while the output will be great. By adding first else if condition the result is worse and output will be grea't. last else if should detect white spaces this condition is tested by != operator and it detects what is not a white space, logicaly using == operator the condition should detect white spaces but it does not occur.
11th May 2023, 3:32 AM
Code Angel
Code Angel - avatar
0
Thank you very much, mission accomplished.🙏🙏🙏
11th May 2023, 7:11 AM
Code Angel
Code Angel - avatar