title: Incorrect output when converting from int to float with static_cast<float> c++
body: <p>I do not understand why my output is coming out as wrong.
  I have attached my code and my result(highlighted the issue)</p>
  <p>I am adding a coin to the insertCoin function in VendingMachine class.
  As soon as I add 10 cents to this function, it prints out error-&gt; Does not accept 10 cents.
  I am converting the input to float using static_cast. I spent some good time on this and at this point, I feel I just cannot see the issue probably because I dont understand some concept.</p>
  <p>Also as a quick background, new to c++ and trying to get my object oriented programming up to date.
  Trying to make a Vending machine product hehe.
  Thank you again !</p>
  <pre><code>#include &lt;iostream&gt;
  #include &lt;string&gt;
  #include &lt;vector&gt;
  #include &lt;unordered_map&gt;
  #include &lt;utility&gt;
  #include &lt;stdlib.h&gt; 
  using namespace std;
  
  class Item
  {
      private:
          string m_name;
          float m_cost;
      public:
          Item(string t_name,float t_cost):m_name(t_name),m_cost(t_cost)
          {
              
          }
          string getName()
          {
              return m_name;
          }
          float getCost()
          {
              return m_cost;
          }
  };
  class VendingMachine
  {
      private:
          vector&lt;Item&gt; m_totalItems;
          unordered_map&lt;string,Item&gt;m_products;
          float m_remainingCharges{0};
          float m_moneyInserted{0};
          size_t itemCount{0};
      public:
          VendingMachine()
          {
              
          }
          void addItemToVendingMachine(string t_name,size_t t_cost)
          {
              float temp=static_cast&lt;float&gt;(t_cost)/static_cast&lt;float&gt;(100);  
              Item item(t_name,temp);
              m_totalItems.push_back(item);
              m_products.insert(make_pair(t_name,item));
          }
          bool chooseProduct(string t_name)
          {
              for(auto item:m_totalItems)
              {
                  if(item.getName()==t_name)
                  {
                      m_remainingCharges=item.getCost();
                      return true;
                  }
                  itemCount++;
              }
              cout&lt;&lt;&quot;Item not currently available: &quot;+t_name&lt;&lt;endl;
              return false;
          }
          void insertCoin(size_t t_coin)
          {   
              float temp=static_cast&lt;float&gt;(t_coin);
              if(t_coin&lt;=50)
              {
                  temp/=100;
                  cout&lt;&lt;temp&lt;&lt;endl;
              }
              if(temp==0.01 or temp==0.05 or temp==0.1 or temp==1.00 or temp==2.00 or temp==0.25 or temp==0.50)
              {
                  m_moneyInserted+=temp;
                  m_remainingCharges-=m_moneyInserted;
              }
              else
              {
                  cout&lt;&lt;&quot;Does not accept: &quot;&lt;&lt; t_coin&lt;&lt;&quot; ,please insert correct coin.&quot;&lt;&lt;endl;
                  return;
              }
          }
          pair&lt;Item,float&gt; getProduct()
          {
              auto item=m_totalItems[itemCount];
              auto itemBack=m_totalItems.back();
              m_totalItems[itemCount]=itemBack;
              m_totalItems.pop_back();
              return make_pair(item,abs(m_remainingCharges));
          }
          
          float refund()
          {
              if(m_remainingCharges&lt;0)
                  return abs(m_remainingCharges);
              else
                  return 0;
          }
          void resetOperator()
          {
               m_remainingCharges=0;
               m_moneyInserted=0;
               itemCount=0;
          }
  };
  int main()
  {
      Item item(&quot;Candy&quot;,0.50);
      cout&lt;&lt;item.getName()&lt;&lt;&quot; &quot;;
      cout&lt;&lt;item.getCost()&lt;&lt;endl;
      VendingMachine machine;
      machine.addItemToVendingMachine(&quot;CANDY&quot;,10);
      machine.addItemToVendingMachine(&quot;SNACK&quot;,50);
      machine.addItemToVendingMachine(&quot;Coke&quot;,25);
      machine.insertCoin(10);
      machine.insertCoin(25);
      machine.insertCoin(50);
      machine.chooseProduct(&quot;CANDY&quot;);
      auto temp=machine.getProduct();
      cout&lt;&lt;temp.first.getName()&lt;&lt;endl;
      cout&lt;&lt;temp.second&lt;&lt;endl;
      machine.resetOperator();
      return 0;  
  };
  </code></pre>
  <p><a href="https://i.stack.imgur.com/vcriv.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/vcriv.png" alt="enter image description here" /></a></p>