Screenshot of the outputs i got for the codeHow to code to separate the whole part and decimal part
I wrote this code but it gives different values at times. I don't know why?
#include <iostream>    
using namespace std;
int main()
{
    float f, a, b;
    int x, y, c;
    cout << "enter the float value" << endl; cin >> f;
    x = (int)f;  cout << "before " << x;
    a = b = f;
    c = 1;
    while (b != int(a))
    {
        b = b * 10;
        a = a * 10;
        c = c * 10;
    }
    y = (f * c) - (x * c);
    cout << "after " << y;
}
enter the float value
22.47
before 22 after 46
user@user:~/cpp$ ./a.out 
enter the float value
2234.127
before 2234 after 126
user@user:~/cpp$ ./a.out 
enter the float value
22.335
before 22 after 334
user@user:~/cpp$ ./a.out 
enter the float value
222.88
before 222 after 88
these are a few values i tried.
 
    