1. ## a dime off.

Hey guys-
I am a dime off on this program and I can't figure out why. Any suggestions? Thanks.

Code:
```#include <stdio.h>

struct dollarsQuartersDimes
{
int dollars,
quarters,
dimes;
};

int main(void)
{
dollarsQuartersDimes dQD1, sum, dQD2 = {  };

printf("\nEnter the dollars, quarters, dimes in purse 1 : \n");

scanf("%d%d%d", &dQD1.dollars, &dQD1.quarters, &dQD1.dimes);

printf("\nEnter the dollars, quarters, dimes in purse 2 : \n");

scanf("%d%d%d", &dQD2.dollars, &dQD2.quarters, &dQD2.dimes);

sum.dollars = dQD1.dollars + dQD2.dollars;
sum.quarters = dQD1.quarters + dQD2.quarters;
sum.dimes = dQD1.dimes + dQD2.dimes;

while (sum.quarters > 3)
{
++sum.dollars;
sum.quarters = sum.quarters - 4;
}

while (sum.dimes > 9)
{
++sum.dollars;
sum.dimes = sum.dimes - 10;
}

while (sum.dimes > 2)
{
++sum.quarters;
sum.dimes = sum.dimes - 2.5;
}

printf("\n   %d dollars %d quarters %d dimes\n+  %d dollars %d quarters %d dimes\n----------------------------\n   %d dollars %d quarters %d dimes \n", dQD1.dollars, dQD1.quarters, dQD1.dimes, dQD2.dollars, dQD2.quarters, dQD2.dimes, sum.dollars, sum.quarters, sum.dimes);

return 0;```

2. Your last loop (mapping dimes to quarters) is the culprit.
Code:
`    sum.dimes = sum.dimes - 2.5;`
will do the subtraction in floating point, and then round toward zero in storing the result to sum.dimes. So, if sum.dimes is positive, this line will subtract 3.

You would be better off converting the input into dollars and cents, and then convert the number of cents back to quarters and dimes. (That's one way, anyway). Otherwise you're being affected by the fact that a quarter is not a whole number of dimes.

3. Like this? But it still does not give me correct change.
Code:
```#include <stdio.h>

struct dollarsQuartersDimes
{
int dollars,
quarters,
dimes;
};

int main(void)
{
dollarsQuartersDimes dQD1, sum, dQD2 = {  };

printf("\nEnter the dollars, quarters, dimes in purse 1 : \n");

scanf("%d%d%d", &dQD1.dollars, &dQD1.quarters, &dQD1.dimes);

printf("\nEnter the dollars, quarters, dimes in purse 2 : \n");

scanf("%d%d%d", &dQD2.dollars, &dQD2.quarters, &dQD2.dimes);

sum.dollars = (dQD1.dollars + dQD2.dollars) * 100;
sum.quarters = (dQD1.quarters + dQD2.quarters) * 25;
sum.dimes = (dQD1.dimes + dQD2.dimes) * 10;

while (sum.quarters > 99)
{
sum.dollars = sum.dollars + 100;
sum.quarters = sum.quarters - 100;
}

while (sum.dimes > 90)
{
sum.dollars = sum.dollars + 100;
sum.dimes = sum.dimes - 100;
}

while (sum.dimes > 20)
{
sum.quarters = sum.quarters + 25;
sum.dimes = sum.dimes - 25;
}

sum.dollars = sum.dollars / 100;
sum.quarters = sum.quarters / 100;
sum.dimes = sum.dimes / 100;

printf("\n   %d dollars %d quarters %d dimes\n+  %d dollars %d quarters %d dimes\n----------------------------\n   %d dollars %d quarters %d dimes \n", dQD1.dollars, dQD1.quarters, dQD1.dimes, dQD2.dollars, dQD2.quarters, dQD2.dimes, sum.dollars, sum.quarters, sum.dimes);

return 0;
}```

4. can anyone help? thanks.

5. Your sum of <coin> is really just pennies now. Change your while loops, accordingly. After you run through the quarters in the while loop, you can't say sum quarters += 25. That's for pennies, and you have already changed pennies back into quarters: so you need sum quarters++;

Same for all the rest of the loops. If you're lost with this, grab some coins with a bit of each type, and work it through by hand AS IF you were the program. Talk to yourself, about what you're doing, as you go through it. The light bulb will come on shortly.

Then look at your while(loopTest), loopTest. Those aren't quite right, are they? If I have 21 cents, I don't have a quarter, see?

If I have 21 cents, I don't have a quarter, see?
wouldn't it be impossible to have 21 cents? so, if it's above 20 cents, it has to be 30 cents, right?

7. ok. here's my changed code.
Code:
```#include <stdio.h>

struct dollarsQuartersDimes
{
int dollars,
quarters,
dimes;
};

int main(void)
{
dollarsQuartersDimes dQD1, sum, dQD2 = {  };

printf("\nEnter the dollars, quarters, dimes in purse 1 : \n");

scanf("%d%d%d", &dQD1.dollars, &dQD1.quarters, &dQD1.dimes);

printf("\nEnter the dollars, quarters, dimes in purse 2 : \n");

scanf("%d%d%d", &dQD2.dollars, &dQD2.quarters, &dQD2.dimes);

sum.dollars = (dQD1.dollars + dQD2.dollars) * 100;
sum.quarters = (dQD1.quarters + dQD2.quarters) * 25;
sum.dimes = (dQD1.dimes + dQD2.dimes) * 10;

while (sum.quarters > 99)
{
sum.dollars = sum.dollars + 100;
sum.quarters = sum.quarters - 100;
}

while (sum.dimes > 99)
{
sum.dollars = sum.dollars + 100;
sum.dimes = sum.dimes - 100;
}

while (sum.dimes > 24)
{
sum.quarters = sum.quarters + 25;
sum.dimes = sum.dimes - 25;
}

sum.dollars = sum.dollars / 100;
sum.quarters = sum.quarters / 25;
sum.dimes = sum.dimes / 10;

printf("\n   %d dollars %d quarters %d dimes\n+  %d dollars %d quarters %d dimes\n----------------------------\n   %d dollars %d quarters %d dimes \n", dQD1.dollars, dQD1.quarters, dQD1.dimes, dQD2.dollars, dQD2.quarters, dQD2.dimes, sum.dollars, sum.quarters, sum.dimes);

return 0;
}```
why am i getting 6 quarters? there should never be more than 3 quarters.

8. I agree with grumpy:
Originally Posted by grumpy
You would be better off converting the input into dollars and cents, and then convert the number of cents back to quarters and dimes.
Create a variable named cents. Compute and store the total number of cents in the quarters and dimes into this cents variable. Then, compute the maximum number of dollars from this total number of cents, adding that figure to the total number of dollars and subtracting 100 times of that from the total number of cents. After that, compute the maximum number of quarters from the remaining total number of cents such that you are left with a whole number of dimes.

9. Why are you using subtraction instead of division? Even if it's not perfect.

<num quarters> / <4 quarters> = <num dollars>

<num dimes> * 10 / <25 cents> = <num quarters> Scaling by a factor of ten eliminates the need to do floating point calculations.

I'm not sure I get it. I mean, every denomination of dollars is important. Even pennies, which everybody hates.

10. Originally Posted by laserlight
Create a variable named cents..
my assignment was to use just the 3 variables i have already used.

11. Originally Posted by whiteflags
Even pennies, which everybody hates.
i am trying to change everything to pennies, and then change it back.

12. Originally Posted by rosemary
my assignment was to use just the 3 variables i have already used.
Does the requirements really say that you are not to use any other variables, or does it say that you must use this struct to store the input and final result?

13. it says "use 3 simple variables".
but, i think i got it.
i should have been starting with the smallest coin instead.
Code:
```#include <stdio.h>

struct dollarsQuartersDimes
{
int dollars,
quarters,
dimes;
};

int main(void)
{
dollarsQuartersDimes dQD1, sum, dQD2 = {  };

printf("\nEnter the dollars, quarters, dimes in purse 1 : \n");

scanf("%d%d%d", &dQD1.dollars, &dQD1.quarters, &dQD1.dimes);

printf("\nEnter the dollars, quarters, dimes in purse 2 : \n");

scanf("%d%d%d", &dQD2.dollars, &dQD2.quarters, &dQD2.dimes);

sum.dollars = (dQD1.dollars + dQD2.dollars) * 100;
sum.quarters = (dQD1.quarters + dQD2.quarters) * 25;
sum.dimes = (dQD1.dimes + dQD2.dimes) * 10;

while (sum.dimes > 24)
{
sum.quarters = sum.quarters + 25;
sum.dimes = sum.dimes - 25;
}

while (sum.quarters > 99)
{
sum.dollars = sum.dollars + 100;
sum.quarters = sum.quarters - 100;
}

sum.dollars = sum.dollars / 100;
sum.quarters = sum.quarters / 25;
sum.dimes = sum.dimes / 10;

printf("\n   %d dollars %d quarters %d dimes\n+  %d dollars %d quarters %d dimes\n----------------------------\n   %d dollars %d quarters %d dimes \n", dQD1.dollars, dQD1.quarters, dQD1.dimes, dQD2.dollars, dQD2.quarters, dQD2.dimes, sum.dollars, sum.quarters, sum.dimes);

return 0;
}```

14. thanks for the help everybody

15. Hint: If you only have three denominations dollars, quarters, and dimes.
The total value will end with either 5 or 0; if 5 it means you have an old number of quarters.

Tim S.