I am learning the basics of the language C, and so far we have covered up to loops. This question is related to my assignment. The problem is I do not understand what the question is asking.

I know the error in the code, but I don't understand what this question is asking me to do? What is an instance? Am I supposed to make a different piece of code? Because I am pretty sure the error is a semantic one(knowledge based rather than syntax). Here is the code anyways just for context: enter image description here

  • 3
    $\begingroup$ An instance is just an input that triggers the problem. $\endgroup$ – Tom van der Zanden Jan 21 '16 at 22:21

As noted by Tom van der Zanden in a comment, and given you already know what's wrong with the code, think of an input that will cause the program to fail, just run the program with that input and you have your instance. Does it make more sense if you think of the phrase, "for instance"?

You may be overthinking it (a good sign actually), if this is just a very basic C language course, they are probably being rather obvious in what they are asking for.

KISS -- Keep It Simple, Sailor

  • $\begingroup$ It does make more sense if you use "for instance". I took python before which is a OOP and they used instance a lot in that course so I was confused about that. If you put it that way, I think my thinking for what an error in the code is might be wrong, because it doesn't make the program crash, but logically it does not make sense. The last digit of a barcode has to be a single digit, but when C outputs the last digit(what this program calculates), the output is two digits instead of a crash in the program. Would this be considered an error? $\endgroup$ – Robo Jan 21 '16 at 22:36
  • $\begingroup$ Oh yeah C is not officially object oriented so I didn't think they meant that -- now there is a raging debate / discussion about doing object oriented things in C for example stackoverflow.com/questions/351733/… ... hope my answer helped, if not be a little more specific or if it turns out the class was asking something else, post your own answer when you find out. meta.stackexchange.com/questions/12513/… $\endgroup$ – JimLohse Jan 21 '16 at 22:40
  • $\begingroup$ You may wish to edit your question to include the followon question in your comment above, it might attract a better answer :) If the program doesn't do what it's supposed to that's an error ... now the question is who made the error, the programmer or the program! EDIT: Now that I look at this closely, without running it, I don't see why it's giving two digits. Suggestion: edit your question to have the actual text, not an image, then people can copy and paste your code and try it, look up MVCE. Use the editor to make it look like code. This is rapidly becoming a StackOverflow question :) $\endgroup$ – JimLohse Jan 21 '16 at 23:33
  • $\begingroup$ stackoverflow.com/help/mcve and stackoverflow.com/help/how-to-ask FYI but nice first question :) $\endgroup$ – JimLohse Jan 21 '16 at 23:36
  • 1
    $\begingroup$ Actually I think your answer is the best: KISS(keep it simple sailor). It turns out you were right, I did overthink it and the error was semantic. As in it was the programmer's fault rather than the program itself. I will keep that slogan in mind :) $\endgroup$ – Robo Jan 22 '16 at 0:30

Not the answer you're looking for? Browse other questions tagged or ask your own question.