It's a simple heuristic problem. You already have the right idea. For a start, if you want to use int (and that's probably a good idea in your case to avoid fp-precision headaches and the need to use a separate fmod), you'll have to scale the floating-point input and your modulo/divisors by 100. Also to cut down on some redundancy, consider using a function like:
// returns number of units and subtracts unit_size * result
// from val
int units(int* val, int unit_size)
{
int num = *val / unit_size;
*val %= unit_size;
return num;
}
printf("No. of P1000 bill: %d\n",units(&x, 1000 * 100) );
printf("No. of P500 bill: %d\n",units(&x, 500 * 100) );
printf("No. of P200 bill: %d\n",units(&x, 200 * 100) );
etc.
That should cut down on redundant code a little bit. Maybe not worth getting too fancy for it and I suspect this is homework. Complete solution:
// returns number of units and subtracts unit_size * result
// from val
int units(int* val, int unit_size)
{
int num = *val / unit_size;
*val %= unit_size;
return num;
}
int main()
{
printf("Enter input: ");
float amount;
scanf("%f",&amount);
int x = (int)(amount * 100.0 + 0.5);
printf("No. of P1000 bill: %d\n", units(&x, 1000 * 100) );
printf("No. of P500 bill: %d\n", units(&x, 500 * 100) );
printf("No. of P200 bill: %d\n", units(&x, 200 * 100) );
printf("No. of P100 bill: %d\n", units(&x, 100 * 100) );
printf("No. of P50 bill: %d\n", units(&x, 50 * 100) );
printf("No. of P20 bill: %d\n", units(&x, 20 * 100) );
printf("No. of P10 coin: %d\n", units(&x, 10 * 100) );
printf("No. of P5 coin: %d\n", units(&x, 10 * 100) );
printf("No. of P1 coin: %d\n", units(&x, 1 * 100) );
printf("No. of 25 cents: %d\n", units(&x, 25) );
printf("No. of 1 cent: %d\n", units(&x, 1) );
return 0;
}
[Edit] If you have trouble understanding pointers, then just do it the way you wrote without using the units function but modify it accordingly to read in a float and multiply by 100 as in the example above.
[Edit] Requested:
int main()
{
printf("Enter input: ");
float amount;
scanf("%f",&amount);
int x = (int)(amount * 100.0 + 0.5); // x stores the user input in cents
int y = x / 100000; // 1000 dollars is 100,000 cents
printf("\nNo. of P1000 bill: %d",y);
x = x % 100000;
...
y=x / 25; // we're working with cents, so 25 = 25 cents
printf("\nNo. of 25 cents: %d",y);
x = (x % 25);
...
}