Originally posted by: notfred
The for inside the while is valid C, but it doesn't make any logical sense.
The "while" condition (where you check to see if element isn't -1) is only evaluated at the completion of each pass through the while loop.
Basically, it only checks to see if element != -1 at the alst closing bracket for the while loop. So, what you're doing is doing 25 "scanf"s, thenchecking to see if "element is" -1, and if it isn't, then you're doing 25 more scanfs.
What you want is this:
int i = 0;
while(element!=-1){
printf("Please enter your first set of numbers (enter -1 to end set)\n");
scanf("%d",element);
a[i-1]=element;
i++;
}
So that it checks after each scanf to see if it should continue.
Also, initialize element before you use it.