3

It says that ' input of 4.2 yields output of 18 \ expected output, but not "18" '. What is the difference between 18 and "18" ?! Here is my code:

#include <stdio.h>
#include <cs50.h>
#include <math.h>
int main(void)
{
 float i; 
 int coins = 0; 
 do {
  printf("How much money is owed?");
  i = GetFloat();
  }
 while( i<=0);
 i *= 100 ; 
 int money = roundf(i) ;

 while(money >=25)
{
 money -= 25;
 coins++ ; 
}
 while(money >=10)
{
 money -= 10;
 coins++;
}
while(money >=5)
{
  money -= 5;
  coins++ ;
 }
while(money >=1)
{
  money -= 1;
 coins++ ; 
}
   printf("%d", coins) ; 
}
2

An unintended benefit of CS50 is learning how to read and adhere to specifications, an invaluable skill if one intends to code for pay :)

From the spec:

Incidentally, so that we can automate some tests of your code, we ask that your program’s last line of output be only the minimum number of coins possible: an integer followed by \n.

Your printf prints an integer.

| improve this answer | |
  • Thankyou! :) This simple bug had baffled me for days! – Manya Agarwal Sep 8 '16 at 21:11

You must log in to answer this question.

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