+ 2
No Numerals
Why doesn’t this code work in C++ ?? Error 4-6! https://sololearn.com/coach/64/?ref=app
13 Réponses
+ 2
https://code.sololearn.com/coZ8EKQ3PDRs/?ref=app
+ 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
+ 1
Pls give clarity about 4-6..?
Line number? Or test cases?
+ 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....
0
It`s work, but has error 4-6.
I sit on this for about 3 hours and I don't understand
0
and?
0
getline(std::cin, str
0
str)*
0
this code has errors 4-6...
0
test cases
- 1
and?
What else your problem..?
You shloud specify that... Daniil Shkarupa
- 3
cin.getline(str,10000);
Remove space before 10000