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.
This is what i made:
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.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); }