# Thread: Trying to figure out how the coin denominations are computed.

1. ## Trying to figure out how the coin denominations are computed.

Code:
```// Import libraries
#include <stdio.h>
#include <math.h>
#include <cs50.h>

int main()
{
// Define an int type variable
int coins_due;
// Create a 'do while' loop
do
{
float change_owed = get_float("Change owed: ");
coins_due = round(change_owed * 100);
}
while (coins_due <= 0);

int quarters = coins_due / 25;
int dimes = (coins_due % 25) / 10;
int nickels = ((coins_due % 25) % 10) / 5;
int pennies = ((coins_due % 25) % 10) % 5;

// Print output
printf("Coins due: %d\n", quarters + dimes + nickels + pennies);
}```

2. How is 'quarters' computed ? I think it is : 41 / 25 = 1.64
How is 'dimes' computed ? Is it 'coins_due' % 25 then that value / 10 , or coins_due % 25 then coins due / 5 ?
How is 'nickels' computed ? Is it coins_due % 25 then that value is passed to to the right, or coins due against each mathematical step individually ?

3. I'd suggest that you do it by hand a few times

How you you pay for something worth \$1.30...

Popular pages Recent additions