mirror of https://github.com/me50/kukemuna.git
51 lines
745 B
C
51 lines
745 B
C
|
|
#include <cs50.h>
|
||
|
|
#include <stdio.h>
|
||
|
|
|
||
|
|
int get_quarters(int cents);
|
||
|
|
int get_dimes(int cents);
|
||
|
|
int get_nickels(int cents);
|
||
|
|
|
||
|
|
int main(void)
|
||
|
|
{
|
||
|
|
int cents, quarters, dimes, nickels, pennies;
|
||
|
|
|
||
|
|
do
|
||
|
|
{
|
||
|
|
cents = get_int("Change owed: ");
|
||
|
|
}
|
||
|
|
while (cents < 0);
|
||
|
|
|
||
|
|
quarters = get_quarters(cents);
|
||
|
|
cents = cents % 25;
|
||
|
|
|
||
|
|
dimes = get_dimes(cents);
|
||
|
|
cents = cents % 10;
|
||
|
|
|
||
|
|
nickels = get_nickels(cents);
|
||
|
|
|
||
|
|
pennies = cents % 5;
|
||
|
|
|
||
|
|
cents = quarters + dimes + nickels + pennies;
|
||
|
|
printf("%i\n", cents);
|
||
|
|
|
||
|
|
return 0;
|
||
|
|
}
|
||
|
|
|
||
|
|
int get_quarters(int cents)
|
||
|
|
{
|
||
|
|
cents /= 25;
|
||
|
|
return cents;
|
||
|
|
}
|
||
|
|
|
||
|
|
int get_dimes(int cents)
|
||
|
|
{
|
||
|
|
cents /= 10;
|
||
|
|
return cents;
|
||
|
|
}
|
||
|
|
|
||
|
|
int get_nickels(int cents)
|
||
|
|
{
|
||
|
|
cents /= 5;
|
||
|
|
return cents;
|
||
|
|
}
|