0

Problem from code coach.

https://www.sololearn.com/coach/55?ref=app. my solution in C++ is below (it's not working) : #include<string> #include<iostream> using namespace std; bool is_letter(char a) { int b; b = (int)a;/*converts char to int(ASCII value)*/ if(b==32)/* 32 is the ASCII value of space */ { return true; } if((b>=65||b<=90)||(b>=97||b<=122)) /*letters 'A' to 'Z' & 'a' to 'z' respectively */ { return true; } return false; }; int main() { string message,hidden; getline(cin,message); int length = message.size(); int i,j=0; for(i=(length-1);i>=0;i--) { if(is_letter(message[i])) { hidden[j]=message[i]; j++; } } cout<<hidden<<endl; return 0; }

15th Jul 2025, 9:25 AM
Rowlet
Rowlet - avatar
3 Respuestas
15th Jul 2025, 10:04 AM
Mila
Mila - avatar
+ 1
Rowlet , i did a try that is easy to read, to understand. for checking if the input characters are alphabetical or a space, we can use the functions: isalpha() and isspace() in an if... conditional. this runs inside a for loop that picks the characters one at a time. inside the if conditional the new string will be built. to reverse the newly created string, we can use the reverse() >> to open the file, do not click the pur text link but the other one. https://sololearn.com/compiler-playground/c39N5ZxZWEIy/?ref=app
15th Jul 2025, 11:30 AM
Lothar
Lothar - avatar
0
Mila , the code you presented has a truncated output - the first letter of each word is missing.
15th Jul 2025, 11:37 AM
Lothar
Lothar - avatar