I have to find the maximum and the minimum using a sentinel controlled repetition.
"maximum” is not working properly. Can anyone help me with some clue about what’s wrong in my code?
#include<stdio.h>
int main() {
int number;
int min;
int max;
do {
printf("Enter a number (-1 to quit): ");
scanf("%d",&number);
if( number >= 0 ) {
if(number < min )
min = number;
if( number > max )
max = number;
}
else if( number < 1 )
printf("the number is not valid \n");
}
while( number != -1 );
printf("Minimum=%d\n",min);
printf("Maximum=%d\n",max);
system("pause");
return 0;
}