0

There's something really weird in the error I get back after running the test. I get that my results are wrong because they're between " "...but I really don't understand where those come from...any hint or someone having faced the same problem?

enter image description here

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

float change;
int cent;
int cent_left;
int quarter = 25;
int quarter_used;
int dime = 10;
int dime_used;
int nickel = 5;
int nickel_used;
int penny = 1;
int penny_used;

int main(void)
{
    /*Prompt change til it's a positive float*/ 
    do
    {
    printf("Hey, how much do I owe you? ");
    change = GetFloat();
    }
    while (change <= 0);

    /*Round change and convert to integer*/ 
    change = change * 100;
    cent = round(change);

    /*Divide cent_of_change by quarter*/
    if (cent >= quarter) 
    {
        quarter_used = cent / quarter;
        cent_left = cent % quarter;
    }
    else if (cent < quarter)
    {
        quarter_used = 0;
        cent_left = cent - quarter_used;
    }

    /*Divide cent_left by dime*/
    if (cent_left >= dime) 
    {
        dime_used = cent_left / dime;
        cent_left = cent_left % dime;
    }
    else if (cent_left < dime)
    {
        dime_used = 0;
        cent_left = cent_left-dime_used;
    }
    /*Divide cent_left by nickel*/
    if (cent_left >= nickel) 
    {
        nickel_used = cent_left / nickel;
        cent_left = cent_left % nickel;
    }
    else if (cent_left < nickel)
    {
        nickel_used = 0;
        cent_left = cent_left-nickel_used;
    }
    /*Divide cent_left by penny*/
    if (cent_left >= penny) 
    {
        penny_used = cent_left/penny;
        cent_left = cent_left%penny;
    }
    int coins = (quarter_used+dime_used+nickel_used+penny_used);
    printf("%i", coins);
}

1 Answer 1

1

One of the hidden lessons in the first few exercises is that programs need to be designed and written to exactly satisfy a program specification. This is particularly important in team programming environments where individuals write separate parts that all have to fit and work together in the end. Close doesn't get the job done. Also, check50 expects exact results. Anything missing or extra, like characters, line feeds, white space, etc., will cause a failure.

So, having said that, did you include a line feed following the output?

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

3
  • I feel so dumb! Thanks a lot! :D Nov 27, 2016 at 20:51
  • Don't feel bad. This is a very common error. But I'll bet you'll be paying special attention to all the details in the future. This is a good thing! ;-)
    – Cliff B
    Nov 27, 2016 at 21:00
  • Promise I will! :) Nov 27, 2016 at 21:24

You must log in to answer this question.

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