# Thread: I am missing something in regards to min?

1. ## I am missing something in regards to min?

This is a program that prompts the user of how many numbers they would like to enter. It is suppose to choose the smallest number. I think my problem is min isn't changing. I have tried a for statement to get min to change in relation to int1 but it doesn't seem to change min. What am I missing here?

Code:
``` #include <stdio.h>
4
5 int main (void)
6
7
8 {
9 float int1 = 0;
10 float min = 1;
11 float a, b;
12
13 printf("How many numbers would you like to compare?\n");
14 scanf("%f",&b);
15
16
17         for ( a = 1; a <= b; a++ ){  /* beginning of for loop */
18
19
20
21 printf("A is to %f\n",a);
22
23
24 printf("Enter intenger\n");
25 scanf("%f",&int1);
26
27
28
29 if ( int1 < min )
30 {
31 min = int1;
32 printf("The minimum is equal to %f\n",min);
33 }
34
35 }/* end for loop */
36
37 printf("The minimum value is %f\n",min);
38 return 0;
39
40 }
41```

How many numbers would you like to compare?
4
A is to 1.000000
Enter intenger
1
A is to 2.000000
Enter intenger
2
A is to 3.000000
Enter intenger
3
A is to 4.000000
Enter intenger
4
The minimum value is 1.000000

2. Thanks for the help.

3. What is your question, exactly? Since you initialize min to 1, and none of the numbers you enter are less than that, min doesn't change. You should initialize min to a very very very very large number, so that you are sure to type something smaller.

4. tabstop you are a genius. I am learning man. I miss the simple things.

5. By the way, a perfect "very very very very large number" would be INT_MAX, if you were using ints. (I'm thinking that you might want ints instead of floats since you prompt for an "integer".)

6. Also, keep note that "a" should be an int. It is the for-loop counter so you need an integer. Having it as float serves nothing. The program loses time in order to make it an integer (propably).
Note important on your case, but since you are learning...it might be useful later on