title: assigning integer values to char array elements
body: <p>The program objective is to convert decimal to hexadecimal
  1)I am having problems assigning integer values to char array elements how is it done. Im getting symbols for my array numerical values. 
  2) How do I initialize my array to spaces? to get rid of garbage and old data in array elements.
  3) could someone explain what my problem is? with integers and chars?
  4) Is cout part of my problem?</p>
  
  <pre><code>#include "stdafx.h"
  #include &lt;iostream&gt;
  #include &lt;iomanip&gt;
  #include &lt;math.h&gt;
  
  int main()
  {
  using namespace std;
  
  // binary declarations
  int x, i, z, n, remainder;
  int result = 0;
  bool loop_cond, remainder_found, octval_found;
  
  // octal declarations
  int octalval,octresult,octremainder,temp_octalval;
  int octloop_cnt;
  bool oct_loop;
  octresult = 0;
  // hexadecimal declarations
  int hexval, hexremainder, temp_hexval;
  int hexloop_cnt;
  bool hex_loop,hexval_found;
  char hexresult[5] = {" "};
  
  cout &lt;&lt; "decimal" &lt;&lt; "\t" &lt;&lt; "binary" &lt;&lt; "\t"&lt;&lt; "octal"&lt;&lt;"\t"&lt;&lt;"hexadecimal"&lt;&lt; endl;
  
  for (i = 1; i &lt;= 256; i++){  
  hexloop_cnt = 0;
  octremainder = 0;
  hexval_found = false;
  hex_loop = true;
  hexloop_cnt = 0;
  while (hex_loop != false){
  
  if (hexval_found != true){
      hexval = i / 16;
      hexremainder = i % 16;
  }
  else {
      temp_hexval  = hexval;
      hexval = hexval / 16;
      hexremainder = temp_hexval % 16;
  }
  
  
  if (hexval == 0){
      switch (hexremainder){
      case 10:
          hexresult[hexloop_cnt] = 'A';
          break;
      case 11:
          hexresult[hexloop_cnt] = 'B';
          break;
      case 12:
          hexresult[hexloop_cnt] = 'C';
          break;
      case 13:
          hexresult[hexloop_cnt] = 'D';
          break;
      case 14:
          hexresult[hexloop_cnt] = 'E';
          break;
      case 15:
          hexresult[hexloop_cnt] = 'F';
          break;
      default:
          hexresult[hexloop_cnt] = (char)hexremainder;
          break;
      }//end switch
      hex_loop = false;
  }//end if
  
  if ((hexval &lt; 16) &amp;&amp; (hexval &gt; 0)){
      switch (hexremainder){
      case 10:
          hexresult[hexloop_cnt] = 'A';
          break;
      case 11:
          hexresult[hexloop_cnt] = 'B';
          break;
      case 12:
          hexresult[hexloop_cnt] = 'C';
          break;
      case 13:
          hexresult[hexloop_cnt] = 'D';
          break;
      case 14:
          hexresult[hexloop_cnt] = 'E';
          break;
      case 15:
          hexresult[hexloop_cnt] = 'F';
          break;
      default:
          hexresult[hexloop_cnt] = static_cast&lt;char&gt;(hexremainder);
          break;
      }//end switch
      hexloop_cnt++;
      switch (hexval){
      case 10:
          hexresult[hexloop_cnt] = 'A';
          break;
      case 11:
          hexresult[hexloop_cnt] = 'B';
          break;
      case 12:
          hexresult[hexloop_cnt] = 'C';
          break;
      case 13:
          hexresult[hexloop_cnt] = 'D';
          break;
      case 14:
          hexresult[hexloop_cnt] = 'E';
          break;
      case 15:
          hexresult[hexloop_cnt] = 'F';
          break;
      default:
          hexresult[hexloop_cnt] = static_cast&lt;char&gt;(hexval);
          break;
      }//end switch
      hex_loop = false;
    } //end if
  
  if ((hexval &gt;= 16)){
      switch (hexremainder){
      case 10:
          hexresult[hexloop_cnt] = 'A';
          break;
      case 11:
          hexresult[hexloop_cnt] = 'B';
          break;
      case 12:
          hexresult[hexloop_cnt] = 'C';
          break;
      case 13:
          hexresult[hexloop_cnt] = 'D';
          break;
      case 14:
          hexresult[hexloop_cnt] = 'E';
          break;
      case 15:
          hexresult[hexloop_cnt] = 'F';
          break;
      default:
          hexresult[hexloop_cnt] = static_cast&lt;char&gt;(hexremainder);
          break;
      }//end switch
      hexval_found = true;
  }//end if 
  
  hexloop_cnt++;
  } //endwhile
  
  
      cout &lt;&lt; i &lt;&lt; "\t" &lt;&lt; result &lt;&lt;"\t" &lt;&lt; octresult&lt;&lt;"\t" &lt;&lt; hexresult&lt;&lt; endl;
      result = 0;
      octresult = 0;
  //      hexresult[5] = { ' ', ' ', ' ', ' ', ' ' };
  }
  
  
  
  cin.clear();
  cin.ignore(255, '/n');
  cin.get();
  
  return 0;
  }
  </code></pre>