Click here to Skip to main content
13,260,108 members (48,148 online)
Rate this:
Please Sign up or sign in to vote.
See more:
int number;
int min_value = 100000;
for (int i = 0; i <= 4; i++)
   Console.WriteLine("Enter a number: ");
   number = Convert.ToInt16(Console.ReadLine());
   if (number < min_value)
      min_value = number;
Posted 3-Dec-12 8:07am
Updated 3-Dec-12 11:54am
Matt T Heffron 3-Dec-12 13:13pm
And your question is????
Things to think about...
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.
So, I answered, please see.
marchest_21 3-Dec-12 13:28pm
You are welcome. It will work for you, for sure. Please consider accepting the answer formally (green button) -- thanks.

1 solution

Rate this: bad
Please Sign up or sign in to vote.

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):[^],[^].

All other integer types have similar property.

With floating-point types, things are way more interesting. You should use NegativeInfinity and PositiveInfinity:[^],[^].

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

Marcus Kramer 3-Dec-12 16:55pm
+5. Well described.
Thank you, Marcus.
CIDev 3-Dec-12 17:32pm
Nice answer, +5
Thank you.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web04 | 2.8.171114.1 | Last Updated 3 Dec 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100