I've been trying to solve this problem for a while but I am completely stuck, so thought I'd ask for help.
This is what I have so far:
#include <stdio.h>
#include <cs50.h>
int main(void)
{
float dollars, coins;
int cents, a, b, c, d;
do
{
printf("Hi! How much change do you need? ");
dollars = get_float();
}
while (dollars <= 0);
(cents = dollars * 100);
(coins = 0);
do
{
(a = cents - .25);
(coins++);
}
while (cents >= .25);
do
{
(b = a - .10);
(coins++);
}
while (a >= .10);
do
{
(c = b - .05);
(coins++);
}
while (b >= .05);
do
{
(d = c - .01);
(coins++);
}
while (c >= .01);
printf("%f\n", coins);
}
I thought my logic was sound--I created different variables for each step of subtracting different coin values and then had the coin number go up by 1 each time.
When I do make greedy, it works with no error. When I then start the program it prompts the user correctly.
however, as soon as I put in a value, the system seems to stall. It doesn't print a value, but it also doesn't reset or prompt me for anything else, it just indents to the next line and then doesn't move, and the ~/workspace/pset1/ does not come back up.
What am I doing wrong? When I try to do the check next to all the frowny faces it says "killed by the system" someone please help! Thanks!!