Made a code that calculated the amount of negative numbers in an array and shows those numbers. The problem is when the program prints out the number, it changes the number a slight bit, adding or subtracting something like 0.003.
I have absolutely no clue as to what's wrong with it, tried asking my professor; she said she didn't know, so I am here.
float col[10];
...
for (int i = 0; i < 10; ++i)
{
scanf_s("%f", &col[i]);
}
...
printf("\n");
printf("There are %d negative numbers\n", ct);
for (int i = 0; i < 10; ++i)
{
if (col[i] < 0)
{
printf("[%d]=%f ", i, col[i]);
}
}
...
Put in -7786.88, command line printed out -7786.888184. It's fine on integers, just prints out a bunch of zeroes after the dot.