# smallest int problem

This is a discussion on smallest int problem within the C Programming forums, part of the General Programming Boards category; I'm to write a program that finds the smallest of several intagers. the first vaulue read specifies the number if ...

1. ## smallest int problem

I'm to write a program that finds the smallest of several intagers. the first vaulue read specifies the number if values remaing for caculation.

here is my code that seems to work put gives me a long negitive number everytime.
Code:
```#include <stdio.h>

int main() // start execution
{
int enter; // the number that determains  specific vaulues remaining
int counter = 1; // counter used in while
int number ; // numbers to be entered
int little; // saves the littlest ineger
int compare; // used to compare numbers

printf ("Please Enter how many sequences:\n");
scanf  ("%d", &enter);

while( counter <= enter ) // numbers to be entered until = enter
{
printf ("Please enter a  positive digit:\n");
scanf  ("%d", &number);

number = compare;

if (number <= compare){ // if stores the littlest int
little = number;

} // ends if

} //ends while

printf ("Our smallest number is %d.\n", little);

return 0; // program ended correctly
} // end main```
thanks,
joe

2. > number = compare;
What does this do to the following comparison?

3. Code:
```		number = compare;

if (number <= compare){ // if stores the littlest int
little = number;

} // ends if

} //ends while```
Here you set number to compare each time. Your compare number is unitialized, thus is garbage. You'll need to do something like have the user enter one number outside the loop to set as compare. Or, you could set compare to the max int 0x7fffffff.

EDIT: Bummer, beaten.

4. i'm sorry i meant to type
Code:
`compare = number;`
hope that makes sense now
but i've been known to be way off before. lol

5. But that is still wrong.

6. ok but how would i go about setting anumber outsdie this loop to be entered

7. > i'm sorry i meant to type
Here's a tip - paste the last thing you ran, directly from your source code.
Not some half-assed "I think this is something like what I tried some time ago".

8. salem i did change it and it aways give the answer of the last number i entered

9. Code:
```printf("Please enter a positive digit:\n");
scanf("%d", &compare);
enter--;
while( counter <= enter ) // numbers to be entered until = enter
{
printf ("Please enter a  positive digit:\n");
scanf  ("%d", &number);```

10. ok here i tried new code
Code:
```#include <stdio.h>

int main() // start execution
{
int enter; // the number that determains  specific vaulues remaining
int counter = 1; // counter used in while
int number ; // numbers to be entered
int little; // saves the littlest ineger
int compare; // used to compare numbers

printf ("Please Enter how many sequences:\n");
scanf  ("%d", &enter);

scanf("%d", &compare);
enter--;

while( counter <= enter ) // numbers to be entered until = enter
{
printf ("Please enter a  positive digit:\n");
scanf  ("%d", &number);

compare = number;

if (number <= compare){ // if stores the littlest int
little = number;

} // ends if

} //ends while

printf ("Our smallest number is %d.\n", little);

return 0; // program ended correctly
} // end main```
i still get the amswer of whatever number i last promted to enter

thank you all so far for your help

11. And you still aren't reading the posts that Salem and I made LONG AGO: (spoon feeding time)

Code:
```	while( counter <= enter ) // numbers to be entered until = enter
{
printf ("Please enter a  positive digit:\n");
scanf  ("%d", &number);

compare = number;```
Originally Posted by Almost Salem
What does this code do?

12. i see but even if i remove this from the code and then recompile it it still hase the effect of saying
Code:
```Our smallest number is "whatever the last number i entered"

so if i tell it 3 on sequence then
lets say first promt i enter 9
second i enter 1
and third i enter 5
five will be the answer as the smallest number```
i need to know why its alway printing the last nember i entered as the answer

13. Remove little from your source. Then, in the if statement, set compare in place of little.

14. thank you thank you thank you kennedy and salem
i guess i over thought this one and had to many int's lol