multiplying final value

hi there can anyone help me with this. i found this program on the internet and have changed it a bit to suit my needs. but the final step I'm caught with is multiplying my final value by 9.
at this stage my program will separate hole numbers from decimals. it will multiply the hole number by 0, this is cancelling it out and leaving me with only the decimals, but i am struggling to multiply my final value by 9. any help is greatly appreciated

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include <iostream>
#include <iomanip>
int main()
{
	printf("enter number");
    float f=1;
    while (f)
    {
        std::cin >> f;
        int i = (int)f;
        std::cout << i*0<< std::setprecision(3) << f - i << std::endl;
        
    }
   
    return 0;
}
Last edited on
I'm surprised that compiles for you.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include <iostream>

int main()
{
    auto prompt = "number? ";
    float value;
	
    while (std::cout << prompt, std::cin >> value)
    {
        int whole = (int)value;
        float decimal = value - whole;
    	
        std::cout << decimal << '\n';
        std::cout << decimal * 9 << "\n\n" ;
    }
}
i had put in the wrong code sorry, i had put up one i had been messing about with trying to get it to work, i changed it there to the one I'm using.
Topic archived. No new replies allowed.