-
still haveing probs
i did what i was told in the last post i made and i still got the very same errors....im really new at this and its something i really want to learn and i need help.....well the problem is how can i get this program to write the numbers i enter in words foward instead of backwards for example when i enter 123 it comes out three two one instead of one two three...what can i do to fix this problem?
Code:
#include <stdio.h>
void main() {
int temp, num, count, i, reg[5], remainder;
char *word[11] = {"one ","two ","three ","four ","five ","six ","seven ","eight ","nine "};
printf("Enter Number\n");
scanf("%d",&num);
temp = num;
count = 0;
while(temp !=0)
{
remainder = temp % 10;
temp = temp / 10;
reg[count] = remainder;
++count;
}
for(i=1; i<=count; ++i) {
switch(i){
case 1:
switch(reg[0]){
case 1:
printf("%s",word[0]);
break;
case 2:
printf("%s",word[1]);
break;
case 3:
printf("%s",word[2]);
break;
case 4:
printf("%s",word[3]);
break;
case 5:
printf("%s",word[4]);
break;
case 6:
printf("%s",word[5]);
break;
case 7:
printf("%s",word[6]);
break;
case 8:
printf("%s",word[7]);
break;
case 9:
printf("%s",word[8]);
break;
default:
printf("Zero");
break;
}
break;
case 2 :
switch(reg[1]){
case 1:
printf("%s",word[0]);
break;
case 2:
printf("%s",word[1]);
break;
case 3:
printf("%s",word[2]);
break;
case 4:
printf("%s",word[3]);
break;
case 5:
printf("%s",word[4]);
break;
case 6:
printf("%s",word[5]);
break;
case 7:
printf("%s",word[6]);
break;
case 8:
printf("%s",word[7]);
break;
case 9:
printf("%s",word[8]);
break;
default:
printf("Zero");
break;
}
break;
case 3:
switch(reg[2]){
case 1:
printf("%s",word[0]);
break;
case 2:
printf("%s",word[1]);
break;
case 3:
printf("%s",word[2]);
break;
case 4:
printf("%s",word[3]);
break;
case 5:
printf("%s",word[4]);
break;
case 6:
printf("%s",word[5]);
break;
case 7:
printf("%s",word[6]);
break;
case 8:
printf("%s",word[7]);
break;
case 9:
printf("%s",word[8]);
break;
default:
printf("Zero");
break;
}
break;
case 4:
switch(reg[3]){
case 1:
printf("%s",word[0]);
break;
case 2:
printf("%s",word[1]);
break;
case 3:
printf("%s",word[2]);
break;
case 4:
printf("%s",word[3]);
break;
case 5:
printf("%s",word[4]);
break;
case 6:
printf("%s",word[5]);
break;
case 7:
printf("%s",word[6]);
break;
case 8:
printf("%s",word[7]);
break;
case 9:
printf("%s",word[8]);
break;
default:
printf("Zero");
break;
}
break;
case 5:
switch(reg[4]){
case 1:
printf("%s",word[0]);
break;
case 2:
printf("%s",word[1]);
break;
case 3:
printf("%s",word[2]);
break;
case 4:
printf("%s",word[3]);
break;
case 5:
printf("%s",word[4]);
break;
case 6:
printf("%s",word[5]);
break;
case 7:
printf("%s",word[6]);
break;
case 8:
printf("%s",word[7]);
break;
case 9:
printf("%s",word[8]);
break;
default:
printf("Zero");
break;
}
}
}
}
-
Did you change anything? No. Solutions were proposed in your other thread.
-
Reverse the loop?
Code:
for ( i = count; i > 0; --i )