title: Decimal conversions to base numbers 2-16 (Binary through Hexadecimal)
body: <p>Hey i'm writing a program that converts decimal numbers into any base unit from binary to hexadecimal (2,3,4,....,15,16). This is what I have so far, running any number from 2 - 15 results in an infinite loop. I was wondering if you had any advice for the rest of my project. When run, this will ask you for two integers, the first should be a decimal integer > 0, the second should be the base type you want it converted to. Any and all advice for completing this would be greatly appreciated! Thank you.</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  
  int main(void){
  
    int x, y, z, c;
  
    printf("Please enter two integers: ");
    scanf("%d", &amp;x);
    scanf("%d", &amp;y);
  
    printf("%d\n", x);
    printf("%d\n", y);
    printf(" \n");
  
    if(y &lt; 2 | y &gt; 16){
      printf("You have entered incorrect information.\n");
             return 0;
    }
    else if(y &gt; 1 &amp;&amp; y &lt; 16){
  
         while(z != 0){
         z = (x/y);
         c = (x%y);
         printf("%d\n", z);
         }
      printf("%d\n", z);
      printf("%d\n", c);
    }
        else if(y == 16){
          printf("%X\n", x);
        }
  
  }
  </code></pre>
  
  <p><em><strong></em>**<em>*</em>**<em>*</em>**<em>*</em>**<em>*</em>**<em>*</em>**<em>*</em>**<em>*</em>*</strong><em>edit</em><strong><em>*</em>**<em>*</em>**<em>*</em>**<em>*</em>**<em>*</em>**<em>*</em>**<em>*</em>**<em>*</em></strong></p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  
  int main(void){
  
    int x, y, z, c, i;
  
    printf("Please enter two integers: ");
    scanf("%d", &amp;x);
    scanf("%d", &amp;y);
  
    printf("%d\n", x);
    printf("%d\n", y);
    printf(" \n");
  
    if(y &lt; 2 || y &gt; 16){
      printf("You have entered incorrect information.\n");
             return 0;
    }
    else if(y &gt; 1 &amp;&amp; y &lt; 17){
  
      while(x != 0){
         c = (x%y);
         x = (x/y);
  
         if( c &gt; 1 &amp;&amp; c &lt; 10){
         printf("%d", c);
  
      }else if( c == 10){
          c = printf("A");
      }else if( c == 11){
          c = printf("B");
      }else if( c == 12){
          c = printf("C");
      }else if( c == 13){
          c = printf("D");
      }else if( c == 14){
          c = printf("E");
      }else if( c == 15){
          c = printf("F");
     }
    }
      printf("\n");
  }
  </code></pre>
  
  <p>This is the progress i've made so far. My problems are this: I cannot get the values A-F to output correctly to represent numbers 10-15. Also I cannot get the integers to be displayed the correct way. I think this is an easy fix, but a command I'm not used to yet. Thank you all for your help, it's been extremely beneficial. </p>
  
  <p><em><strong></em>**<em>*</em>**<em>*</em>**<em>*</em></strong><em>edit 2 <strong></em>**<em>*</em>**<em>*</em>**<em>*</em>***</strong></p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  
  int main(void){
  
    int x, y, z, c; //Sets up variables to be used in program
  
    printf("Please enter two integers: "); //Asks for user input
    scanf("%d", &amp;x);
    scanf("%d", &amp;y); //stores input
  
    printf("%d\n", x);
    printf("%d\n", y);
    printf(" \n");
  
    if(y &lt; 2 || y &gt; 16){
      printf("You have entered incorrect information.\n");
             return 0;
    } //bug checks
  
    else if(y &gt; 1 &amp;&amp; y &lt; 17){
  
      while(x != 0){
         c = (x%y);
         x = (x/y); // Loops numbers until a 0 value is reached, can be used with
                    // any Base
  
       if( c == 10){
          c = printf("A");
      }else if( c == 11){
          c = printf("B");
      }else if( c == 12){
          c = printf("C");
      }else if( c == 13){
          c = printf("D");
      }else if( c == 14){
          c = printf("E");
      }else if( c == 15){
          c = printf("F");
      }else{
          printf("%d", c);
      }
       // Returns for each remainer option
      }
      printf("\n");
    }
  }
  </code></pre>
  
  <p>OKay third time is the charm. The only problem I have with my code now is that i cannot figure out how to make it output in reverse order, the proper order. Ignore my second edit, I solved that myself. Any input would be awesome. I don't really know how I'm going to get it to come out reversed. Thanks everyone!</p>