still haveing probs

This is a discussion on still haveing probs within the C Programming forums, part of the General Programming Boards category; i did what i was told in the last post i made and i still got the very same errors....im ...

  1. #1
    Registered User
    Join Date
    Oct 2006
    Posts
    2

    Question 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;
    
    
    }
    }
    }
    }

  2. #2
    Registered User Tonto's Avatar
    Join Date
    Jun 2005
    Location
    New York
    Posts
    1,465
    Did you change anything? No. Solutions were proposed in your other thread.

    ╔╗╔╦══╦╗╔╦══╦╗
    ║╚╝║╔╗║╚╝║╔╗║║
    ║╔╗║╠╣║╔╗║╠╣╠╣
    ╚╝╚╩╝╚╩╝╚╩╝╚╩╝

    codez http://code.google.com/p/zxcvbn/

  3. #3
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,006
    Reverse the loop?
    Code:
       for ( i = count; i > 0; --i )
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. 2 simple C++ probs
    By alikoolg in forum C++ Programming
    Replies: 4
    Last Post: 03-18-2009, 09:02 PM
  2. Replies: 2
    Last Post: 11-04-2007, 11:55 AM
  3. WM_TIMER probs (FPS Calculations)
    By C+noob in forum C++ Programming
    Replies: 0
    Last Post: 10-02-2005, 02:39 AM
  4. databse iterator probs
    By mouse163 in forum C++ Programming
    Replies: 1
    Last Post: 04-27-2003, 02:45 PM
  5. magic sq probs
    By scuba22 in forum C++ Programming
    Replies: 2
    Last Post: 11-18-2002, 08:40 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21