0

So this is the code I have now:

#include <stdio.h>
#include <cs50.h>        
#include <math.h>
int main (void)
{
float c;
int  i;

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

//Round for each type of coin
c *= 100;
i = round(c);
    //quarters
    while (i >= 25)
    {
        i++;
        i -= 25;
    }

    //dimes
    while (i >= 10)
    {
        i++;
        i -=25;
    }

    //nickels
    while (i >=5)
    {
        i++;
        i -= 25;
    }       

    //Penny
    while (i >=1)
    {
        i++;
        i -= 25;
    }


    //print coins
    printf("%i\n", i);
}

And this is the output: enter image description here

What do I do?? Please help!

2
  • Read your code very carefully and critically.Looks like you copy/pasted the while loops, because they all look the same and they shouldn't. – DinoCoderSaurus Apr 22 '19 at 17:59
  • lol, @DinoCoderSaurus, reaad his next question. ;-) – Cliff B Apr 22 '19 at 23:26
1

Why does the code increment the amount of change, i, each time it subtracts the value of a coin from it? You should be using a separate variable to track the number of coins.

You must log in to answer this question.

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