title: floating number sum in c++
body: <p>I have created this program to convert string to float the program run ok but when I try 1995.1995 it output 1995.2 but it works for other strings like 1
  can any explain the reason?</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;iomanip&gt;
  using namespace std;
  bool isValid(char c) {
      if (c == '.')
          return true;
      if (c &gt;= '0' &amp;&amp; c &lt;= '9')
          return true;
      return false;
  }
  int main()
  {
      char input = '0';
      while (isValid(input)) {
  
          float result = 0;
          bool isFraction = false;
          float divideBy = 1;
          cout &lt;&lt; "please enter string to convert : " &lt;&lt; endl;
          cin &gt;&gt; input;
          while (true)
          {
              if (input == '.') {
  
                  isFraction = true;
              } 
              else {
  
                  int intInput = input - '0';
                  if (isFraction) {
                      divideBy = divideBy * 10;
                      result = result + intInput / divideBy;
                  }
                  else {
                      result = result * 10 + intInput;
                  }
              }
              if (cin.peek() == '\n')
                  break;
              cin &gt;&gt; input;
          }
          cout &lt;&lt; "Your input is : " &lt;&lt; result &lt;&lt; endl;
      }
      return 0;
  }
  </code></pre>