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;
}