Help with very simple C program

This is a program asking a user to input numbers. It then displays the minimum and maximum values. The first set of code works fine. (Actually, it doesn't work how I'd like to. I run it in linux. I enter the set of numbers. Hit enter and nothing happens, and THEN hit ctrl+d and it shows the solution. That's the only way I can get it to work.)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include<stdio.h>
#include<limits.h>
#include<ctype.h>

int main()
{
	int number=0;
	int min=INT_MAX;
	int max=-1;
	printf("Enter any set of numbers: ");
	while(EOF!=scanf("%d",&number))     //Loop finding max and min.
	{
			if(number>max)
			{
				max=number;
			}
			else if(number<min)
			{
				min=number;
			}
	}

	printf("The max value is %d and the minimum value is %d \n",max,min);
	

	return 0;
}



Now I altered my code up a bit so if the user inputs a letter, I want to tell them that they must input an integer instead.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include<stdio.h>
#include<limits.h>
#include<ctype.h>

int main()
{
	int number=0;
	int min=INT_MAX;
	int max=-1;
	printf("Enter any set of numbers: ");
	while(EOF!=scanf("%d",&number))     //Loop finding max and min.
	{
		if(isdigit(number))    //If the entered character isn't an integer, tell them to input integer and terminate
		{
			if(number>max)
			{
				max=number;
			}
			else if(number<min)
			{
				min=number;
			}
		}
		else
		{
			printf("Please input an integer.");
			return 0;
		}
	}

	printf("The max value is %d and the minimum value is %d \n",max,min);
	

	return 0;
}


So technically neither code works, but the bottom code actually doesn't work at all. Any suggestions? Thanks in advance!
its the line "EOF!=scanf("%d",&number)" and its not doing what you expect it to be doing.

For scanf, if the input does not match the format specifier (the %d) then you discard the input from the stream, meaning you're already ignoring anything that isnt a long int to start off with.
Topic archived. No new replies allowed.