I wrote this piece of code. Generally it's just a declaration of four integers and the corresponding formulas. One line for each int:

int q25 = cents/25 - cents%25/100;

int q10 = (cents - q25*25)/10 - (cents - q25*25)%10/100;

int q05 = (cents - q25*25 - q10*10)/5 - (cents - q25*25 - q10*10)%5/100;

int q01 = cents - q25*25 - q10*10 - q05*5;

Upon submitting, I lost points for style. So I ran the code in sandbox with style50. This is style50's feedback. I don't understand it at all... how was the code supposed to look?

style50 output for the code

Thanks a lot in advance!

1 Answer 1


This output is indeed not very helpful. I guess they create a "properly formatted" version of the script and apply a generic diff tool (you can learn more about those later in the course, in the "similarities/more" problem). Easy solutions coming to my mind would cause serious limitations.

It's usually considered good style to add a single space on both sides of a binary operator (operators with two operands, like *, %, +, ==, <, &&, =, and a few more, while for example ! negation operator is an unary operator and grouped with its only operand). I assume if you add those spaces, the diff will work better.

With a more reasonable output, you'd usually remove what is red and replace it with what is green.

As a dirty trick, you could add lines with unique garbage in between as comments, like

code line 1
// totallygarbageweuris-mnasdfjoiwert9w0etlsa
code line 2
// moregarbagelkfiasdf39j234calljenny867-5309
code line 3

The garbage line would be same in the compared code versions, likely preventing it from mixing the lines. Remove the bogus comments before submitting, and don't forget adding reasonable comments, so another person reading the code might better understand it. Another person might be you next month.

You must log in to answer this question.

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