String table and printing english equivalent
I have a question that is still boggling my mind. Since my lecturer never gives me the answer. So, I decided to ask the board about this. Sorry if the post is a bit messy. Im quite new. The question goes like this.
"Write a C program that creates a string table containing the English words for the digits 0 through 9. Using this table, allow the user to enter a digit and then have your program display the word equivalent. The program has to allow the user to enter again the digit if he enters something other than digits 0 through 9."
I have created a code. I don't know if I answered the question. Can anyone rectify me if I didn't?
Code:
#include <stdio.h>
void num_to_english(char* zero, char* one, char* two, char* three, char* four,
char* five,char* six, char* seven, char* eight, char* nine);
void main()
{
char a,b,c,d,e,f,g,h,j,k;
num_to_english(&a,&b,&c,&d,&e,&f,&g,&h,&j,&k);
getchar();
}
void num_to_english(char* zero,char* one, char* two, char* three, char* four,
char* five, char* six, char* seven, char* eight, char* nine)
{
int number,i;
zero = "zero"; one = "one"; two = "two"; three = "three"; four = " four";
five = "five"; six = "six"; seven = "seven"; eight = "eight"; nine = "nine";
printf("Please insert a number from 0-9 : ");
scanf("%d", &number);
printf("The %d equivalent in english is : ",number);
if(number>=0&&number<=9)
{switch(number)
{case 0:
printf("%s", zero);
break;
case 1:
printf("%s", one);
break;
case 2:
printf("%s", two);
break;
case 3:
printf("%s", three);
break;
case 4:
printf("%s", four);
break;
case 5:
printf("%s", five);
break;
case 6:
printf("%s", six);
break;
case 7:
printf("%s", seven);
break;
case 8:
printf("%s", eight);
break;
default:
printf("%s", nine);}}
else
{printf("is out of range. Please re-enter.\n\n");
main();}
}
Thank you so much!! :)