Why Didn’t I Remember or Think of That?
Jun 16th, 2006 by Brian A. Thomas
I was working on Exercise 4-2 in Murach’s C# 2005 which at one point has you figure out how to display the largest, smallest and mid point of a series of invoices. Finding the largest is fairly straight forward, assume it is 0 at the start and compare it using Math.Max (at this point we can’t use the if or any other control structure, just the math class). The smallest invoice was the first trick, and they give a hint, but for some reason I couldn’t figure out what they meant by using the “MaxValue of the Decimal class.” Why I couldn’t figure remember that a member is something that follows a dot operator is beyond me, but the solution was simple enough in the end, decimal smallestInvoice = decimal.MaxValue; to set the high number for smallestInvoice and then compare it to the invoice total using the Math.Min.
The next point of confusion for me was finding the mid point. Perhaps it is because I was woke up at 6 a.m. after going to bed at 2 a.m., but for the life of me I couldn’t figure out how to find the mid point in a set of numbers. I was like “I know the mid point of 1000 and 500 is 750, but how do I know that using math?” For some reason I kept attacking it from the wrong direction and eventually had to use the Internet to find the formula. At this point I smacked my head and thought “why didn’t I remember or think of that?”
Incidentally, in case you forgot, the formula is (X+Y)/2… though most of the examples on the Internet were for number lines, such as finding the midpoint of say (12,3) and (4,7) which is (8, 5)… thinking in terms of Algebra that becomes (x1,y1) and (x2,y2) = (midX,midY) and the formula for that is midX=(x1+x2)/2 and midY=(y1+y2)/2.. all of which I note here mostly for future reference for myself.







i love you Brian A. Thomas
Um…. I am guessing this is because the above helped, in which case you are most welcome.