A college freshman I know taking an intro to computer science class asked me for help on one of his homework assignments. I read through a few times and I'm embarrassed to admit I don't know what they're asking for. Here's the question:
Given below is the outline of a loop. Finish the program so that it will read in x and y values, validate them (by continuing to prompt the user until they enter the correct values), and run such that the given assertions will always be true. Include the loop invariant assertion at the four points in your program where it must be true. You may not use the multiplication operator, except in the given assert(...) statements.
assert(x>0 && y>0);
while(...)
{
assert(sum == i*(x+1));
...
...
}
assert(sum == y*(x+1));
I didn't know what a loop invariant was so I googled and read the Wikipedia article. From that I gather the first assert statement is telling me that I should not allow x and y to ever be negative for the duration of the loop. Truthfully I'm stuck at this point. Can someone help me understand what they're asking for here?