I am very new to c but I have to create a program for school and for that, I need to know how many decimal numbers are in a number but when I try this a bunch of random numbers come from the 4th dimension and I don't know how to fix it, can anybody help me?
Here is the code:
int main(void) {
float test = 1.567;
while (test != 0){
test = test * 10;
test = test - (int)test;
printf("%f\n",test);
}
}
Edit: I'm running on windows 10, and I'm using repl.it to program and run it. This is the output I get
0.670000
0.700001
0.000008
0.000076
0.000763
0.007629
0.076294
0.762939
0.629395
0.293945
0.939453
0.394531
0.945312
0.453125
0.531250
0.312500
0.125000
0.250000
0.500000
0.000000
Edit 2: The assignment is that we have to create a program where you have to enter an amount of money and it tells you how many 2 euro coins, 1 euro coins, etc. you need to get that amount and because you can't have 4.63454 euro I wanted to make sure that you can only enter 2 decimal numbers otherwise it would throw an error. So TLDR: you enter the number via the keyboard, but the same thing happens then.