title: Convert string to float or integer without using built in functions (like atoi or atof)
body: <p>I'm new to C++ and our teacher asked us to get a function that does the above title. So far I've got a function that converts a string to an integer, but I have no idea about how to <em>modify</em> it to make it work if the numbers in the string would represent a float.</p>
  
  <pre><code>int convert(char str[], int size) {
      int number = 0;
      for (int i = 0; i &lt; size; ++i) {
          number += (str[i] - 48)*pow(10, (size - i - 1));
      }
      return number;
  }
  </code></pre>
  
  <p>If I run:</p>
  
  <pre><code>char myString[] = "12345";
  convert(myString, 5);
  </code></pre>
  
  <p>I get:</p>
  
  <pre><code>12345
  </code></pre>
  
  <p>But if I run:</p>
  
  <pre><code>char myString[] = "123.45";
  convert(myString, 5);
  </code></pre>
  
  <p>I get:</p>
  
  <pre><code>122845
  </code></pre>
  
  <p>How could I modify my program to work with floats too? I know <em>convert</em> function is meant to return an int so, should I use two more functions? </p>
  
  <p>I was thinking about one that determinates if the string is inteded to be converted to an integer or a string, and the other that'll actually convert the string to a float.</p>