OK so I am stuck on greedy, I am trying to do small steps at a time and using my logic I thought I was right but seems I am incorrect about my formula. I start with the quarter section and only use printf to see if it outputs a correct response but it does not. I have no idea what i am doing wrong . here is my code. It works when you put in any amount before a decimal but any amount that would be after does not work.

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

  int main(void){

  int quarter = 25;
   //int dime = 10;
   //int nickel = 5;
   int result, converted,leftOver;

printf("Enter amount ");
int userInput = get_float();

converted = round(userInput * 100); 
result = converted / quarter;
leftOver = converted % quarter;

printf("%i ", result);
printf("%i ", leftOver);   

  • I'm a newbie, but let's see if I can help... For decimals (change owed) you would have to use a float. You can use "int" for the coin values and for the counter (coins returned).
    – Nikki L.R.
    Jan 19 '17 at 20:55
  • I had to use a while loop because that was the easiest way for me... "while change is less or equal to" and then the coin.
    – Nikki L.R.
    Jan 19 '17 at 21:01

The problem is here:

int userInput = get_float();

you're getting a float, the variable you're storing it into should be a float. Because you store it into an int, if you enter 4.2, it's going to be stored as 4.

The rest looks fine to me

You must log in to answer this question.

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