Thread: New to programming.. question about "continue;"

  1. #1
    Registered User
    Join Date
    Sep 2012
    Posts
    49

    New to programming.. question about "continue;"

    Hello, I am trying to implement a program where I receive an integer input such as "123" and return an English output such as "one two three." I was told to get rid of the continue statement in my code below, but I am having a tough time structuring the loops without it. It is probably pretty simple but I am missing it. Any ideas?

    Code:
    #include <stdio.h>  
    int main(int argc, char *argv[]) 
    {   
    int number,pos,pow10;   
    const char *word;   
    
    printf ("Enter your number.\n");   
    scanf ("%i", &number);   
    
    for(pos = 9; pos >= 0; pos--)
     {     
    switch(pos) 
    {       case(9): pow10 = 1000000000;
             break;       
           case(8): pow10 = 100000000;
             break;
           case(7): pow10 = 10000000;
             break;
           case(6): pow10 = 1000000;
             break;
           case(5): pow10 = 100000;
             break;
           case(4): pow10 = 10000;
             break;
           case(3): pow10 = 1000;
             break;
           case(2): pow10 = 100;
             break;
           case(1): pow10 = 10;
             break;
           case(0): pow10 = 1;
             break;
           default: return -1;
             break;
         }     
    
    if(number < pow10 && pos != 0) 
    continue;
         switch((number / pow10) % 10)
     {
           case(9): word="nine";
             break;
           case(8): word="eight";
             break;
           case(7): word="seven";
             break;
           case(6): word="six";
             break;
           case(5): word="five";
             break;
           case(4): word="four";
             break;
           case(3): word="three";
             break;
           case(2): word="two";
             break;
           case(1): word="one";
             break;
           case(0): word="zero";
             break;
           default: return -1;
            break;
         }
         printf("%s ",word);
       }
       printf("\n"); }
    Last edited by sdbuilt; 09-06-2012 at 05:39 PM.

  2. #2
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    this is a tip, only. I have not run your program.


    Code:
    if(number < pow10 && pos != 0)      //the original
    continue;
    
    if(the dog weighs < 10 lbs && the dog's color != white)  //the original, reconstructed
       continue;   //skip the switch statement
    
    
    if(the dog weighs >= 10 lbs && the dog's color == white)  //turning the logic around
    {
          switch(...)  //run the switch statement
              ...
    }

  3. #3
    Registered User
    Join Date
    Sep 2012
    Posts
    49
    Ah I see now, I actually have to go a little further than that Adak and change it to

    Code:
    if (number >= pow || pos ==0)
    {
    switch(...)
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 1
    Last Post: 02-23-2010, 08:15 AM
  2. "Press any key to continue" Error on console
    By c# Student in forum C# Programming
    Replies: 2
    Last Post: 10-19-2006, 10:04 AM
  3. Using "continue" (basic language problem)
    By DominicTrix in forum C++ Programming
    Replies: 5
    Last Post: 09-06-2004, 06:10 PM
  4. Replies: 7
    Last Post: 08-28-2003, 10:15 PM
  5. "itoa"-"_itoa" , "inp"-"_inp", Why some functions have "
    By L.O.K. in forum Windows Programming
    Replies: 5
    Last Post: 12-08-2002, 08:25 AM