Repeating float number randomly interrupted

88 Views Asked by At

In my code I have the following line:

monthInt = intRate / 12.0f; 

Where intRate (yearly interest rate) is a float assigned by user input, in this case the user chose 4, which turned into 4.0 repeating. However, monthInt (monthly interest rate) ends up getting 0.333333343. Where is the 4 coming from?

#include <iostream>
using namespace std;
int main()
{
    float intRate;
    float monthInt;
    cout << endl << "Please enter the annual interest rate as a percentage: ";
    cin >> intRate;
    monthInt = intRate / 12.0f;
    return 0;
}

I don't believe that any of the other lines of code are relevant to the problem as they don't interact with these variables yet.

0

There are 0 best solutions below