0

At first, I thought this was because my code was spitting out 419 when it multiplied 4.2 by 100. I fixed this issue, but I'm still getting the "\ expected output, but not..."

It's showing me some odd stuff on that error after the "but not". It should say just "Give the customer %d coin(s)." The error is showing me:

"41\n1\n2\n3\n4\nGive...",
"1\n0\n0\n0\n1\nGive...",
"15\n0\n1\n2\n2\nGive...",
"160\n6\n7\n7\n7\nGive...",
"2300\n92\n92\n92\n92\nGive...", and
"420\n16\n18\n18\n18\nGive..."

It shows this for 0.41, 0.01, 0.15, 1.6, 23, 4.2. It does end the phrase but has those weird bits of something at the beginning. It only gives this, though, when I run check50. By itself, the program runs perfectly and gives the right answer.

What might be causing this? Is it a general issue with check50 or is there probably actually something seriously wrong?

Thanks!

0

1 Answer 1

1

Let me guess. In your program, after the user has inputted the change he needs, you have

printf("%d\n", number_of_coins);

where number_of_coins is the name of the variable you use to store the number of coins obviously.

Then, for each coin value, you calculate how many of those coins you are gonna need, and then printf those too.

That's your problem. According to the specification

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. Consider the below representative of how your own program should behave, wherein underlined text is some user’s input.

jharvard@appliance (~/Dropbox/pset1): ./greedy
O hai! How much change is owed?
0.41
4

You probably have as output:

jharvard@appliance (~/Dropbox/pset1): ./greedy
O hai! How much change is owed?
0.41
41
1
2
3
4
Give the user...

Your output should be the exact asked by the course.

If this answers your question please accept it by clicking the gray check-mark to the left, so that it becomes green. You can also vote it up by pressing the up arrow above the check-mark. And don't forget to keep coding!

1
  • 1
    Ah, that did it. I had all those printf's for my own benefit to check to make sure everything was doing the arithmetic correctly. Deleting all of them fixed that.
    – Chris
    Commented Aug 26, 2015 at 15:29

You must log in to answer this question.

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