|
Homework 2.6, I answered as follows (albeit belatedly, as I was away in Geneva. I assume now that I'll have to opt for the final making 100%, otherwise the 50% for homework will be brought down by the 0% grade here?):
I then get this error on submission: Incorrect. Something went wrong while running your procedure. Well, certainly not when I run it! Any ideas why I'm getting this error? Would also appreciate knowing what will happen about the homework situation, I couldn't avoid missing the deadline - but it's also frustrating to have overall grade completely hanging on final exam. Thanks. |
|
Your code does not assign anything to last if the target string does not exist in the search string, so it's attempting to return a value that it can't find, which gives an error. A suggestion: include a line that tests for that exact case and return -1 if the target isn't present. As for the homework, one homework grade is dropped, so if this is the only homework you miss, your homework grade can still be averaged in with your final. |
|
Your code doesn't terminate properly if it doesn't enter the while loop. Also I had to edit your post to fix your code formatting. When you post code, you want to make sure it's formatted properly so we can read it. Remember to test against multiple cases (as the grader does) rather than just one or two. Try to cover all the possible types of inputs that you expect. Try running your code against these:
Regarding the homework:
|
|
Ah, thanks. Sorted. Edit: Thanks Valek too. Just saw your reply. I definitely should have checked for more circumstances.. but I just couldn't see where it was missing before forbiddenvoid pointed it out. Thanks again. |
|
Okay sorry for this, but I must be incredibly tired, or something. I'm having the same issue with my answer to HW 2.7:
I can't see any problem with it, no matter how many numbers I put in for n. |