+ 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 ??

5th Apr 2020, 5:52 PM
Nurullah Aydın
Nurullah Aydın - avatar
20 Respostas
0
increment i when a match is found to skip printing it. if(sentence[i]==array[t]){ cout<<array2[t]; i++; }
5th Apr 2020, 6:58 PM
Bahhaāµ£
Bahhaāµ£ - avatar
+ 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.
5th Apr 2020, 7:06 PM
Bahhaāµ£
Bahhaāµ£ - avatar
+ 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 ?
5th Apr 2020, 7:22 PM
Nurullah Aydın
Nurullah Aydın - avatar
0
Ä°t fixed my problem but my code still cant pass the tests on the Code coach.Could you see another bug ?
5th Apr 2020, 7:03 PM
Nurullah Aydın
Nurullah Aydın - avatar
0
Should I write code also for ten ?
5th Apr 2020, 7:07 PM
Nurullah Aydın
Nurullah Aydın - avatar
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
5th Apr 2020, 7:09 PM
Bahhaāµ£
Bahhaāµ£ - avatar
0
But how? When add my array to 10 it will occur fail because of 10 is two char
5th Apr 2020, 7:11 PM
Nurullah Aydın
Nurullah Aydın - avatar
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.
5th Apr 2020, 7:19 PM
Bahhaāµ£
Bahhaāµ£ - avatar
0
that will not work if there are other numbers greater than 10. example 11 will be one1.
5th Apr 2020, 7:49 PM
Bahhaāµ£
Bahhaāµ£ - avatar
0
it want us to convert only numbers that are between 0-10.isn't it ?
5th Apr 2020, 7:52 PM
Nurullah Aydın
Nurullah Aydın - avatar
0
the input can be anything, but you have to only convert numbers <=10.
5th Apr 2020, 7:55 PM
Bahhaāµ£
Bahhaāµ£ - avatar
0
ohh I am in trouble now.I think I need to change my code completely. Can I save from here with just adding?
5th Apr 2020, 7:57 PM
Nurullah Aydın
Nurullah Aydın - avatar
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.
5th Apr 2020, 8:05 PM
Bahhaāµ£
Bahhaāµ£ - avatar
0
What is the type of the array,is it string ?
5th Apr 2020, 8:06 PM
Nurullah Aydın
Nurullah Aydın - avatar
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.
5th Apr 2020, 8:15 PM
Bahhaāµ£
Bahhaāµ£ - avatar
0
I will try but I have no idea that how can I store the words of user entered sentence in array
5th Apr 2020, 8:19 PM
Nurullah Aydın
Nurullah Aydın - avatar
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.
5th Apr 2020, 8:25 PM
Bahhaāµ£
Bahhaāµ£ - avatar
5th Apr 2020, 8:30 PM
Bahhaāµ£
Bahhaāµ£ - avatar
0
https://code.sololearn.com/cVyOxIVP87aZ/#cpp I think I cant do this :/
5th Apr 2020, 8:44 PM
Nurullah Aydın
Nurullah Aydın - avatar
0
Ok90094321
7th Apr 2020, 3:02 PM
Richo Bonou
Richo Bonou - avatar