The code has 3 different errors. First, as you count the coins, you are post-incrementing and assigning the values, as in this:
q = coins++;. That means that when you want to add a coin to the count, it is actually assigning the current value in coins to q, and then adding 1 to coins. The
++ should come before the variable to pre-increment ( increment before executing the assignment) instead of post-increment.
The second problem is that the variables q, d, n and p are not initialized to 0, so they contain garbage data. If change is a value that causes a coin denomination to be skipped, (i.e., no dimes), then that coin variable (d, in this case) will not be properly set and the garbage value will be used in processing the next coin denomination.
Third, the code is highly dependent on there being at least one coin of each type. If any coin type is not required (i.e., no nickels), it's going to lose track of whatever count existed before that coin.
The last two problems are a result of trying to cascade from one coin type to the next. Instead, you should use one single variable to count the coins from beginning to end. By doing so, there will no longer be a problem if a coin type isn't needed to make change.
A side note. Even after you fix these issues, it will fail check50. The hidden lesson in this pset is that you need to write your code to exactly the specification - no extra or missing spaces, whitespace, text, etc. In this case, it says to print out the number of coins. Your addition of text,
the ammount of coins to use for change is: will cause the failure.
If this answers your question, please click on the check mark to accept. Let's keep up on forum maintenance. ;-)