This program is supposed to output the digits of a number in English. so if the user inputs 100, the output should be "one, zero, zero".
i cant figure out whats wrong with my program...
Code:
#include <stdio.h>
void get_string( char buffer[], int size ) ;
char english_number( char string[] ) ;
void get_string( char buffer[], int size )
{
char character;
int j = 0;
do /* Get a character until newline or */
{ /* we run out of characters. */
character = getchar() ;
buffer[j] = character ;
++j;
}
while ( character != '\n' && j < size ) ;
while ( character != '\n' ) /* Get rid of extra characters. */
character = getchar() ;
buffer[j - 1] = '\0' ; /* Replace newline with the null-byte. */
}
void main( void )
{
char line[81] ;
int count ;
char result, one, two, three, four, five, six, seven, eight, nine ;
printf( "Enter a number : " ) ;
get_string( line, 81 ) ;
for( count = 0 ; line[count] != '\0' ; count++ )
{
english_number( line ) ;
printf( "%s\n", line ) ;
}
}
char english_number( char string[] )
{
int count ;
char one, two, three, four, five, six, seven, eight, nine ;
for( count = 0 ; string[count] != '\0' ; count++ )
{
if( string[count] == '1' )
return( 'one' ) ;
else if ( string[count] == '2' )
return( 'two' ) ;
else if ( string[count] == '3' )
return( 'three' ) ;
else if ( string[count] == '4' )
return( 'four' ) ;
else if ( string[count] == '5' )
return( 'five' ) ;
else if ( string[count] == '6' )
return( 'six' ) ;
else if ( string[count] == '7' )
return( 'seven' ) ;
else if ( string[count] == '8' )
return( 'eight' ) ;
else if ( string[count] == '9' )
return( 'nine' ) ;
}
}
is there something wrong with the else if statements? or is there another way to do it? or am i completely lost?