0
#include<cs50.h>
#include<stdio.h>
int main ()
{
    **float f;
    do**
    {
        **printf("O hai! How much change is owed?\n");
        f = get_float();**
    }
    **while(f<0);

    int c=0;
    f=f*100;
    double round(double f);

    while(f>=25)
    {
        f=f-25;
        c++;
    }
    while(f>=10)
    {
        f=f-10;
        c++;
    }
    while(f>=5)
    {
        f=f-5;
        c++;
    }
    c=c+f;**
    ***printf("%i", c);***

}
2
  • Question - why do you have * around a lot of the code? For example: ***printf("%i",c);***. Also, could you provide a screenshot of your gradebook? Thank you. May 29 '17 at 1:43
  • Im sorry. While posting my code here I was using the site's tools to highlight certain parts of my code , and instead it just printed these '*'. May 29 '17 at 17:04
0

I doubt it's working perfectly. I took your code, removed those strange **, and used check50 as mentioned in the task description:

~/workspace/freestyle/ $ check50 2016.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 "22"
:) rejects a negative input like -.1
:) rejects a non-numeric input of "foo"
:) rejects a non-numeric input of ""

https://sandbox.cs50.net/checks/ef10ab59402f448d886ce7883e5c039b

Not only do you not provide a new-line character (\n) after your output, also the value for input 4.2 is wrong (output 22 vs. expected 18).

You write double round(double f);, which is a function declaration. You are not meant to do that, as round is already declared in math.h, which you need to include. Also, you would have to call round, like int cash_in_cents = round(100 * cash_in_dollars); (adjust to your own variable names).

4
  • Okay. Thank you. But it does provide the correct output in 5 out of 6 of the above cases right ? How come check50 says theyre wrong as well. May 29 '17 at 17:10
  • Hi, @VasviSharma. To get to your question, check50 counted you wrong because it was looking for the new-line \n after your output. Note that check50 is very specific in what it wants. :-) May 29 '17 at 18:05
  • @VasviSharma The link provided by check50 is sometimes more valuable than the console output. Take for example Expecting the following on standard out — 4\n ... but received the following on standard out instead — 4 (taken from the link in my answer). The missing \n is clearly visible. Note that sometimes Regular Expression sequences appear in the expected output (like ciphertext:\s* with \s* meaning any number of whitespace or none at all).
    – Blauelf
    May 30 '17 at 8:00
  • @SuperNovaCoder @ Blauelf Alright. Thanks a lot for helping out :) May 31 '17 at 4:06

You must log in to answer this question.

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