This code i made is a cent converter from 5 to 95 cents. The problem i'm receiving is when the 'cents' function is sent back to the 'main' function it only prints one line. It seems to just print the first if construct that complies with the statement. Is there anyway i can have this function print multiple cent values? For example if 60 cents was entered it would only print '50c', and i want it to print '50c' and '10c' instead, thanks.
Code:
#include <stdio.h>
int x;
void check(int x)
{
if( x < 5)
printf("Less then 5 cannot be calculated\n");
else if(x > 95)
printf("More then 95 cannot be calculated\n");
return;
}
void cents(int x)
{
if( x/5 >= 1)
printf("5c");
else
if( x/10 >= 1)
printf("10c");
else
if( x/20 >= 1)
printf("20c");
else
if( x/50 >= 1)
printf("50c");
else
return;
}
int main()
{
int amount;
printf("Please enter the amount of cents(5 to 95): ");
scanf("%d%*c", &amount);
printf("You're change is: \n");
check(amount);
cents(amount);
return(0);
}