How to break down numbers

so im just new here and i really need the help now.

This is a problem from a book, and im really having a hard time doing it.
So here's the problem. I need to write a function that receives a floating point number representing the change from a purchase. The function will pass back the break down in dollar bills,half dollar, quarters,dimes, nickels and, pennies.

But here in the Philippines we only have 10 peso coin, 5 peso coin, 1 peso coin, 25 cents, 10 cents, and 5 cents. I only manage to do the break down of the 10 5 and 1 and i stuck cause i get get the 25 10 and 5 cents.

Thanks for the help.


#include "stdafx.h"
#include "stdio.h"
#include "stdlib.h"

int five_peso (int change);
int ten_peso (int change);
int one_peso (int change);

int _tmain(int argc, _TCHAR* argv[])
{
float change;

printf("Enter change = ");
scanf_s("%f", &change);

printf("your change is \n %d ten peso, %d five peso and, %d one peso \n", ten_peso(change),five_peso(change), one_peso(change));
printf("%.2f twenty five cents", twentyfive_cents(change));

return 0;
}
int ten_peso (int change)
{
return (change /10);
}

int five_peso (int change)
{
return ((change - ((change / 10)*10))/5);
}

int one_peso (int change)
{
int answer;
answer = (change - ((change /10)*10));
if (answer < 5)
return answer ;
else
return ((change - ((change /10)*10))-5);
}
Last edited on
Topic archived. No new replies allowed.