You've got a double array named payments[M], and a char array named l_plates[M][N], both of which have been sorted.
For the contents of l_plates that are THE SAME, you want the corresponding SUM of contents of payments stored on the first of equal slots, while turning the remaining equal slots into '-1' every time. How do you go about this?
Example: (why isn't this working?)
Code:
for (beg = 0, end = 0; beg < M-1; beg++) {
for (end = beg + 1; (end < M) && (strcmp(l_plates[beg], l_plates[end]) == 0); end++) {}
if (end > beg + 1) {
payments[beg] = sum_pay(payments, beg, end);
}
}
double sum_pay (double payments[M], int start, int finish) {
int i, sum;
for (i = start, sum = 0; (i < M) && (i < finish); i++) {
sum = sum + payments[i];
}
for (i = start + 1; i < finish; i++) {
payments[i] = -1;
}
return (sum);
What changes have to be made so that this code would work? I've been trying to figure this out for hours now...
Edit: this is just part of the code, of course. The whole thing does compile, and things seem to be working great until I get to this part (at least according to gdb).