# PSET1 Cash Outputting negative number?

I have a very bizarre problem I am experiencing. When I input any number the output by my program is as such:

coins: 2

mQ + mD + mN + pN = -1055516176

When I run the program again it outputs nothing and I have to restart the terminal. Any guesses as to what's going on?

Any advice is appreciated! Thanks all.

Here is my code for PSET1 - Cash:

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

#include <cs50.h>

#include <math.h>

int main(void)

{

float coins;

do
{
coins = get_float("coins: ");
}
while (coins <= 0);

int quarters = 25, dimes = 10, nickels = 5, pennies = 1;
int dQ, mQ, dD, mD, dN, mN, dP;

int cents = round(coins * 100);

dQ = (cents / quarters);
mQ = (cents % quarters);

while (dimes <= mQ)
{
dD = (mQ / dimes);
mD = (mQ % dimes);
}
while (nickels <= mD)
dN = (mD / nickels);
mN = (mD % nickels);
}
while (pennies <= mN)
{
dP = (mN / pennies);
}
printf("dQ + dD + dN + dP = %i\n", dQ + dD + dN + dP);
return 0;
}
``````

Program will eventually get stuck in an infinite loop. If input is .41 (41 cents), program will be stuck here `while (dimes <= mQ)` because neither `dimes` not `mQ` changes inside the loop; so the while (`10 < 16`)expression is always true.
Does the program really need while loops? Each coin amount is calculated, and the remainder is used as the "base" for the next coin. It doesn't appear to need `while`s.