# Need help with final touch

• 03-04-2009
MaaaTtY
Need help with final touch
hey what i tried to do was write a program that asks user to enter integer numbers, keeps track of the largest and smallest numbers entered, ends if 0 is entered. Then prints the number of entries, min, and max.

Code:

``` #include "stdio.h" void main() {         int max;         int min;         int index = 0;         int input;                 printf("Enter integer numbers: ");                         scanf("%d\n", &input); //initialze the "input" variable                 index++;                 max = input; //initialize "max"                 min = input; //initialize "min"                 while (input != 0) {                                                 scanf("%d", &input);                         index++;                                                 if(input>max){                                 max=input;                         } //end of if 1                         if(input<min){                                 min=input;                         } //end of if 2                 } //end of 'while' loop                                 printf("\n The number of integers you entered was:  %d", index);                        printf("\n The largest integer you entered was:  %d", max);                        printf("\n The smallest integer you entered was:  %d", min);                        }```
It almost works fine expect one problem, it always returns the min value as 0, because its what i use to terminate the loop. how can i prevent it from doing this? i was thinking i could make the if statement say something like: "if input is less than min but not equal to 0", i just dont know how this would be done.
• 03-04-2009
Salem
Detect the end of the loop as you input the value, not after you've "processed it by mistake".
• 03-04-2009
MaaaTtY
Quote:

Originally Posted by Salem
Detect the end of the loop as you input the value, not after you've "processed it by mistake".

how?
• 03-04-2009
hk_mp5kpdw
Quote:

Originally Posted by MaaaTty
how?

Depends, could be as simple as testing for 0 immediately after the scanf and breaking out of the loop at that point... or reordering some of the code in the loop so that the scanf is at the bottom of the while loop code block.
• 03-04-2009
Salem
> how?