+ 1
How can I turn into the digits to word on a sentence?
https://code.sololearn.com/cI4X0OyT3wiG/#cpp Here is my code.I completed most of it but there is a bug.When we enter a sentence like 'Micheal 1',the output was 'Micehal one1'. I dont want to see 1 at there.Could you help me ??
20 Respuestas
0
increment i when a match is found to skip printing it.
if(sentence[i]==array[t]){
cout<<array2[t];
i++;
}
+ 1
oh, I wasn't aware you were trying to solve a code coach.
the bug is if you have a number like 10 it will print one zero. because it checks one digit at a time.
+ 1
https://code.sololearn.com/c6qLxAs2THG0/#cpp
I did something like this for ten it is working but it still cant pass the three tests :/ Could you check this link for me ?
0
Ä°t fixed my problem but my code still cant pass the tests on the Code coach.Could you see another bug ?
0
Should I write code also for ten ?
0
yes that is what the code coach says :
Take a phrase and replace any instances of an integer from 0-10 and replace it with the English word that corresponds to that integer.
0-10
0
But how? When add my array to 10 it will occur fail because of 10 is two char
0
you can split the sentence by spaces so each word will be by itself. then convert them to int and compare them to 0-10 and print.
0
that will not work if there are other numbers greater than 10.
example 11 will be one1.
0
it want us to convert only numbers that are between 0-10.isn't it ?
0
the input can be anything, but you have to only convert numbers <=10.
0
ohh I am in trouble now.I think I need to change my code completely. Can I save from here with just adding?
0
try splitting the sentence into an array that has each word. and convert only from 0-10.
i.e sentence = "12 months in 1 year"
split by spaces
arr [] = {"12", "months", "in", "1", "year"} ;
now you can check if an element is a number or not then convert if 0-10.
0
What is the type of the array,is it string ?
0
yes a string or array of characters like in C,.
you could change your char array[10] to int
and use atoi() to convert the string for comparison.
0
I will try but I have no idea that how can I store the words of user entered sentence in array
0
you can use strtok()
i.e
char sentence[100];
char *split_sentence[100];
char *ptr;
int l = 0;
//split string to array
ptr = strtok (sentence ," ");
while (ptr != NULL) {
split_sentence[l++] = ptr;
ptr = strtok (NULL, " ");
}
you store the input in sentence.
and the split sentence will be stored in split_sentence.
let me write you an example in Playground.
0
https://code.sololearn.com/cVyOxIVP87aZ/#cpp
I think I cant do this :/
0
Ok90094321