+ 2

No Numerals

Why doesn’t this code work in C++ ?? Error 4-6! https://sololearn.com/coach/64/?ref=app

21st Sep 2020, 6:43 PM
Daniil Shkarupa
Daniil Shkarupa - avatar
12 Antworten
+ 2
https://code.sololearn.com/coZ8EKQ3PDRs/?ref=app
21st Sep 2020, 6:49 PM
Daniil Shkarupa
Daniil Shkarupa - avatar
+ 2
This can be easily done by arrays you are making your code so much complex #include <iostream> using namespace std; int main() { string str; getline(cin,str); string no="0123456789"; string no1[]={"zero","one","two","three","four","five","six","seven","eight","nine"}; for(int i = 0;i<str.length();i++) for(int j = 0;j<no.length();j++) (str[i]==no[j])?(str.replace(i,1,no1[j])):((str[i]=='1' && str[i+1]=='0')?(str.replace(i,2,"ten")):("")); cout<<str; return 0; } Here is the solution But I recommend you to don't use this code Just understand it then make a version of your then submit it Code coach are added on sololearn to practice So don't copy it if you really want to learn
23rd Sep 2020, 1:13 AM
Coder
Coder - avatar
+ 1
Pls give clarity about 4-6..? Line number? Or test cases?
22nd Sep 2020, 3:52 PM
Jayakrishna 🇮🇳
+ 1
It seems working fine but only i guess, when input number is last charecter then you may printing array value out of index. So Try this if(i<strlen(str)) // i!=strlen(str)) //both same conditions cout << str[i]; But you have lot redundant condition making confusion. You can do same in case 1,if i+1 is 0 for ten else one.. Alternatively....
22nd Sep 2020, 5:40 PM
Jayakrishna 🇮🇳
0
It`s work, but has error 4-6. I sit on this for about 3 hours and I don't understand
21st Sep 2020, 6:50 PM
Daniil Shkarupa
Daniil Shkarupa - avatar
0
and?
21st Sep 2020, 8:07 PM
Daniil Shkarupa
Daniil Shkarupa - avatar
0
getline(std::cin, str
22nd Sep 2020, 10:56 AM
Vitalii Rudkin
Vitalii Rudkin - avatar
0
str)*
22nd Sep 2020, 10:56 AM
Vitalii Rudkin
Vitalii Rudkin - avatar
0
this code has errors 4-6...
22nd Sep 2020, 12:46 PM
Daniil Shkarupa
Daniil Shkarupa - avatar
0
test cases
22nd Sep 2020, 3:53 PM
Daniil Shkarupa
Daniil Shkarupa - avatar
- 1
and? What else your problem..? You shloud specify that... Daniil Shkarupa
22nd Sep 2020, 12:21 PM
Jayakrishna 🇮🇳
- 3
cin.getline(str,10000); Remove space before 10000
21st Sep 2020, 8:05 PM
Jayakrishna 🇮🇳