Originally Posted by
nonpuz
lets not forget about using arrays....anytime you're working with small numbers (less than a couple thousand..) you can often use an array as a lookup table , rather then hundreds of if statements or switch cases:
You mean something like this? (solution in 20 lines)
Code:
#include <stdio.h>
#include <stdlib.h>
int main (void)
{
int number = -1;
char *asword[] = {"zero","one","two","three","four","five","six","seven","eight","nine"};
printf("Enter a number from 0 to 9 : ");
scanf("%d",&number);
if ((number < 0) || (number > 9))
{
printf("Error: Only numbers 0 - 9 are allowed\n");
exit(0);
}
printf("You entered the number %s\n",asword[number]);
return 0;
}
This may be just a bit too advanced for our learning friend...
He really needs to get solid on the raw syntax (if() while() etc.) first.