0

the file compiles, runs, and asks the question just fine. However, after a number is input, just a blank line comes up. I've tried to see the problem but I just can't. A little help please. Thanks

    #include<stdio.h>
    #include<cs50.h>
    #include<math.h>

    int main(void) {   

    //finds the minimum number of coins for change
    float change;
    int count = 0, amount;

    do {
    printf("Amount of change: ");
    change = GetFloat();
    }
    while(change < 0);

    //change change into cents
    change *= 100;
    amount = (int) round(change);

    //Quarters
     while (change >= 25)
    {
       count++;
       amount-= 25;
    }


    //Dimes
    while (change >= 10)
    {
       count++;
       amount-= 10;
    }


    //Nickels
    while (change >= 5)
    {
       count++;
       amount-= 5;
    }


    //Cents 
    while (change >= 1)
    {
       count++;
       amount-= 1;
    }

    printf("%i", count);
    return 0;
}
0
  change *= 100;
 ......
 while (change >= 25)
    {
       count++;
       amount-= 25;
    }

in your while loop, change always worth the same whereas inside, amount decreases, so your while loop never ends, you must impose the condition in while so that it ends, and this is done by decreasing change instead of amount, you can dispense amount just doing:

int change = round(change);
0

You have an infinite loop, you're checking change but change is never altered.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .