Please can someone tell me what's wrong with my code on spy life | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Please can someone tell me what's wrong with my code on spy life

#include <iostream> using namespace std; int main() { string sentence; string new_sentence; int i, j = 0, len; getline(cin, sentence); len = sentence.length(); char sentences [len]; for(int i = 0; i <= len; i++){ if((sentence[i] >= 'a' && sentence[i] <= 'z') || (sentence[i] >= 'A' && sentence[i] <= 'Z') || sentence[i] == ' '){ sentences[j] = sentence[i]; j++; } } new_sentence = sentences; for(i = 0, j = new_sentence.length()-1; i < (new_sentence.length()/2); ++i, --j){ int temp; temp = new_sentence[i]; new_sentence[i] = new_sentence[j]; new_sentence[j] = temp; } for(i = 0; i < new_sentence.length()+1; i++){ cout << new_sentence[i]; } return 0; }

23rd Jan 2020, 9:56 PM
Oluwatowo Rosanwo
Oluwatowo Rosanwo - avatar
2 Answers
+ 1
Well many people have the same proplem and are not able to solve test case 5. Could anyone tell what is test case 5
14th Mar 2020, 2:28 PM
Alexander Thiem
Alexander Thiem - avatar
+ 1
Thanks for the fast Answer Alexandr!! But I still don’t find the Mistake of my code. Could you please help a 15 year old guy?!? #include <iostream> using namespace std; int main() { int length=0; string b; getline(cin,b); while(b[length]!=*(new char)){ length++; } char a[length]; int pos=0; for(int i=0;b[i]!=*(new char);i++) { if(b[i]>64&&b[i]<91) { a[pos]=b[i]; pos++; } if(b[i]>96&&b[i]<123) { a[pos]=b[i]; pos++; } if(b[i]==32) { a[pos]=b[i]; pos++; } } char c[pos]; for(int i=0;i<pos;i++) c[i]=a[pos-i-1]; cout << c; return 0; } */
14th Mar 2020, 5:22 PM
Alexander Thiem
Alexander Thiem - avatar