I keep getting an error with the code below and I don't know why.
int sum(struct node *head)
{
int total = 0;
struct node *temp = head;
while (temp != NULL)
{
total += temp->data;
temp = temp->next;
}
}
Error C4716 'sum': must return a value
sumpromises to return anintbut does not. Areturn total;at the end of the function is probably in order. I suspect a function with a name likesumshould return the calculated sum, and you went through all the trouble of computing it.}}. That's a poor way to place a curly brace, it gets lost in the jumble of code and doesn't indicate where a function ends. I suggest you give up this style asap, because it will make collaborating with other developers harder.