> while (((*p).next != nil)&&((*p).next < average))
You're comparing a pointer with an integer. It's exactly what the my compiler said about that line. You should compare it with the value of 'num' contained in that node that you're currently comparing it with...
Secondly, you don't have to always use the syntax (*pointer).member, instead there's a shorthand version ->. let me show you an example:
p->next = blahblah; // same as (*p).next except it's easier on the eyes
John A
Vampirical Lurker
7,630 posts since Apr 2006
Reputation Points: 2,240
Solved Threads: 339
What I'm saying is that you can't just compare p->next, because that's a pointer. You would want to compare the average to p->next->num, which is the actual value contained in the node.
John A
Vampirical Lurker
7,630 posts since Apr 2006
Reputation Points: 2,240
Solved Threads: 339
>Only prob is it is not printing the new list after the numbers are deleted that are below average.
You've got a few little bugs below...
q=first;
p=(*q).next; // why set this to the next node?
// do you realize that you will skip the first node?
// by comparing the 'next' node, you skip another node, so the first 2 nodes are skipped (from the first bug)
while (((*p).next!= nil)&&(p->next->num < average))
{
q=p;
p=(*p).next;
}
//endwhile
// because you were comparing the 'next' node,
// 'p' will be one node behind and this statement will always fail
if ((*p).num > average)
{
first = p;
}
else
{
first = nil;
}
John A
Vampirical Lurker
7,630 posts since Apr 2006
Reputation Points: 2,240
Solved Threads: 339
>I copied the first part of the problem's program, but it is coming out different.
Copying and pasting is a BAD idea, and should be avoided whenever possible.
>Any ideas?
Well, you could start by taking your original program that works, and splitting the parts of code into functions. Then once you have that working, all you have to do is call the functions from the main() function. It's also a lot easier to see your mistakes when you've split up the code.
And by the way, it's very annoying when you don't use code tags, so if you started using them, it would be much-appreciated. Thanks.
John A
Vampirical Lurker
7,630 posts since Apr 2006
Reputation Points: 2,240
Solved Threads: 339
Its first time for you, not for us.
And btw, you already must have got the warning for not adding code tags. Remember to use them in the future.
~s.o.s~
Failure as a human
11,938 posts since Jun 2006
Reputation Points: 3,281
Solved Threads: 734
Thank -- not sure why you are being snotty for I think that for a first time Linked Lister, I am not doing too bad of a job.
Joe wasn't being snotty, he gave you the suggestions you needed, all 3 of them. And we have no idea what this means:
I copied the first part of the problem's program, but it is coming out different.
In what way? When you copy and paste you should get exactly what you copied.
And I'm going to add one new request -- you need to format your code . As it is, your code is difficult to follow without indentation. To get the best help, make your code easier to read.
WaltP
Posting Sage w/ dash of thyme
10,506 posts since May 2006
Reputation Points: 3,348
Solved Threads: 944