Hi, i want to make a program that lets the user input as many numbers as they like and terminates when the user enters "EXIT" and prints the largest & smallest input, heres my code:
#include<stdio.h>
#include<string.h>
#include <stdlib.h>
int main (){
int input;
int min,max,a=0;
char exit[] = "EXIT";
char exit2[100];
min = INT_MAX;
max = INT_MIN;
do{
printf ("Insert any value[type EXIT to end]: ");
scanf("%d",&input);
gets (exit2);
fflush(stdin);
if (strcmp(exit2,exit)==0){
break;
}
if (max < input){
max = input;
a++;
}
if (min > input){
min = input;
}
}while (strcmp(exit2,exit)!=0);
if (a==0){
return 0;
}else{
printf ("Smallest :%d\n",min);
printf ("Biggest : %d\n",max);
getchar();
}
return 0;
}
now this code works fine except when the first input is not a number it prints some weird number for some reason(-858993460)...so i added this to line 24
if(scanf("%d",&input)!=1 && strcmp(exit2,exit)!=0){
//blablabla
}
but its still not working, can anyone tell me why and how to fix it please thanks