0

plz take a look at my code ```

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

int main(void)
{
    int coins=0;
    float change=0;
    int counter=0;
    int qr=25;
    int dm=10;
    int ni=5;
    int pn=1;


    do
    {
        change=get_float("Please enter the change to be returned:- ");

    }
    while(change<0);

    change=round(change*100);

    int changer=(change);
    //printf("%d",changer);

    while(counter<changer)
    {
        while(changer%qr>25)
        {
            coins++;
            changer=changer-qr;
            //printf("%d\n",changer);
        }
        while(changer%dm>10)
        {
            coins++;
            changer=changer-dm;
            //printf ("%d\n",coins);
        }
        while(changer%ni>5)
        {
            coins++;
            changer=changer-ni;
        }
        while(changer%pn>1)
        {
            coins++;
            changer=changer-pn;
        }
        counter++;
    }    
    printf("%d",coins);
}

``` What is wrong in my code?This is my first time on Stack exchange so I apologise if I made any mistake

1
change=round(change*100);

So, this line takes the float change, multiplies it by 100 and rounds it to get rid of the problem of how numbers are imperfectly stored in floats, and then stores it back in a float. Do you see a problem with that?

There may be other issues, but I'll let you work through them one at a time, if any.

If this answers your question, please click on the check mark to accept. Let's keep up on forum maintenance. ;-)

1
  • OK I made a change as follows:- ```int changer=round(change*100); what about my approach to solution? Mar 4 '18 at 9:30

You must log in to answer this question.

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