0

check50 gives weird error please help

#include <cs50.h>
#include <stdio.h>
#include <math.h>
int main(void)
{
    int amount,n25,n10,n5,n1,total;
    int rem;
    float gamount;
    printf("O hai!");
do{
    printf("How much change is owed?\n");
    gamount = GetFloat();
}while(gamount<0);
    amount = (int) round(gamount *100.00);
    rem = round(amount);
    n25 =(int) rem /25;
    rem = rem %25;
    n10 = rem /10;
    rem = rem%10;
    n5 = rem /5;
    rem = rem%5;    
    n1 = rem /1;
    rem = rem%1;
    total = n25+n10+n5+n1;
    printf("%d",total);
    return 0;
}

check50 output:

*~/workspace/pset1/ $ check50 2015.fall.pset1.greedy greedy.c
:) greedy.c exists
:) greedy.c compiles
:( input of 0.41 yields output of 4
   \ expected output, but not "4"
:( input of 0.01 yields output of 1
   \ expected output, but not "1"
:( input of 0.15 yields output of 2
   \ expected output, but not "2"
:( input of 1.6 yields output of 7
   \ expected output, but not "7"
:( input of 23 yields output of 92
   \ expected output, but not "92"
:( input of 4.2 yields output of 18
   \ expected output, but not "18"
:) rejects a negative input like -.1
:) rejects a non-numeric input of "foo"
:) rejects a non-numeric input of ""
https://sandbox.cs50.net/checks/f9c8501c99a848df82d8bd0df231a6ea

i tried changing the printf("%d",total) statement to printf(total) but it results in compile error compiling using

clang -ggdb3 -O0 -std=c11 -Wall -Werror -Wshadow greedy.c -lcs50 -lm -o greedy

0

1 Answer 1

0

Common mistake. Adherence to specification is of utmost importance when programming for a grade or a boss or a customer. How does your output differ from what is required by 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.

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