+ 1

No Numerals

Hi All , my code pass all test cases unless the #6 test case. Do you have any idea how to solve it? #include <stdio.h> #include <ctype.h> #include <string.h> #include<stdlib.h> int main() { char str1[100]; scanf("%[^\n]s",str1); for (int i =0; i < strlen(str1); i++){ if (isalpha(str1[i])>0) printf ("%c", str1[i]); else if (str1[i] == ' ') printf (" "); else if ((str1[i] == '1') && (str1[i+1] !='0')) printf ("one"); else if (str1 == '2') printf ("two"); else if (str1 [i] == '3') printf ("three"); else if (str1[i]== '4') printf ("four"); else if (str1[i] == '5') printf ("five"); else if (str1[i]== '6') printf ("six"); else if (str1[i] == '7') printf ("seven"); else if (str1[i]== '8') printf ("eight"); else if (str1[i] == '9') printf ("nine"); else if ((str1[i] == '1' && str1[i+1] =='0')){ printf ("ten"); i++; } } return 0; }

13th Nov 2021, 10:54 PM
ElkanaM
ElkanaM - avatar
4 Réponses
+ 1
str1 == '2' should be str1[i] == '2'
14th Nov 2021, 12:21 AM
Simon Sauter
Simon Sauter - avatar
+ 1
What is the question of this exercise?
13th Nov 2021, 11:46 PM
Apollo-Roboto
Apollo-Roboto - avatar
+ 1
Apollo-Roboto You write a phrase and include a lot of number characters (0-9), but you decide that for numbers 10 and under you would rather write the word out instead. Can you go in and edit your phrase to write out the name of each number instead of using the numeral? Task: 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. Input Format: A string of the phrase in its original form (lowercase). Output Format: A string of the updated phrase that has changed the numerals to words. Sample Input: i need 2 pumpkins and 3 apples Sample Output: i need two pumpkins and three apples
13th Nov 2021, 11:47 PM
ElkanaM
ElkanaM - avatar
0
G'day ElkanaM did you get this working? I think your code doesn't check that a digit is not the start of a number >11, nor does it check if a word like "1st" is in the input. I know test case 3 in C language has 10 as part of the input (I missed checking for that) but my code passed test case 6.
13th Feb 2022, 5:14 AM
HungryTradie
HungryTradie - avatar