12,627,002 members (35,258 online)
Rate this:
See more:
```int number;
int min_value = 100000;
for (int i = 0; i <= 4; i++)
{
Console.WriteLine("Enter a number: ");
if (number < min_value)
min_value = number;

Console.WriteLine(number);
}```
Posted 3-Dec-12 8:07am
Updated 3-Dec-12 11:54am
v2
Matt T Heffron 3-Dec-12 13:13pm

What happens when you enter "100001" (so it is > min_value)? What do you think SHOULD happen?
What happens when you enter "abc"? Again, what do you think SHOULD happen?

Exactly. Absolutely wrong.

But it explains why OP asks this question -- this is exactly the problem.
--SA

--SA
marchest_21 3-Dec-12 13:28pm

thanks

You are welcome. It will work for you, for sure. Please consider accepting the answer formally (green button) -- thanks.
--SA

Rate this:

## Solution 2

Please see comments to the questions — by Matt T Heffron and mine. This is the problem.

And here is the solution: instead of pointless "100000" use `int.MaxValue` (and, to find the maximum, start with `int.MinValue`):
http://msdn.microsoft.com/en-us/library/system.int32.minvalue.aspx[^],
http://msdn.microsoft.com/en-us/library/system.int32.maxvalue.aspx[^].

All other integer types have similar property.

With floating-point types, things are way more interesting. You should use `NegativeInfinity` and `PositiveInfinity`:
http://msdn.microsoft.com/en-us/library/system.double.negativeinfinity.aspx[^],
http://msdn.microsoft.com/en-us/library/system.double.positiveinfinity.aspx[^].

The fundamentally important and amazing feature is: infinity values correctly compare with non-infinite values with operators '>', '<', '>=', '<=' and '=='!

—SA
v4
Marcus Kramer 3-Dec-12 16:55pm

+5. Well described.

Thank you, Marcus.
--SA
CIDev 3-Dec-12 17:32pm

Thank you.
--SA

Top Experts
Last 24hrsThis month
 OriginalGriff 292 ppolymorphe 220 CPallini 185 Peter Leow 171 F-ES Sitecore 136
 OriginalGriff 1,274 ppolymorphe 866 John Simmons / outlaw programmer 590 CPallini 513 Peter Leow 469