Program for outputting an int in english

I'm supposed to write a program that takes in an integer and outputs the numbers in english. IE: 932 would output nine three two.
The way I tried to write the code is with an array to store the numbers with a for loop to take in each number and a for loop to output the numbers.

The program never outputs anything in the for loops though, after I enter the length the program ends.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
  #include<stdio.h>
int main(void)
{
    char number[30];
    int n, i, length, checknumber;
    printf("How many characters is your integer?\n");
    scanf("%d", &length);
    for(i=0; i++; i<length)
    {
        printf("Enter integer number %d (Only numbers 0-9)\n", i+1);
        scanf("%s", &number[i]);
    }
    for(n=length; n--; n>0)
    {
        number[n]= checknumber;
        switch(checknumber)
        {
            case '0':
                printf("zero ");
                break;
            case '1':
                printf("one ");
                break;
            case '2':
                printf("two ");
                break;
            case '3':
                printf("three ");
                break;
            case '4':
                printf("four ");
                break;
            case '5':
                printf("five ");
                break;
            case '6':
                printf("six ");
                break;
            case '7':
                printf("seven ");
                break;
            case '8':
                printf("eight ");
                break;
            case '9':
                printf("nine ");
                break;
        }
    }
    return 0;
}
Last edited on
line 8: your for loop is screwed up. Should be for( i = 0; i < length; i++ )

same problem on line 13
Last edited on
agh thanks
Registered users can post here. Sign in or register to post.