I have this really long method:
public decimal decDiscount(QuoteData quoteData)
{
if (TotalChapter7(quoteData) >= 7499)
return 5300;
else if (TotalChapter7(quoteData) >= 7449)
return 5300;
else if (TotalChapter7(quoteData) >= 7399)
return 5250;
else if (TotalChapter7(quoteData) >= 7349)
return 5200;
else if (TotalChapter7(quoteData) >= 7299)
return 5200;
else if (TotalChapter7(quoteData) >= 7249)
return 5150;
else if (TotalChapter7(quoteData) >= 7199)
return 5100;
else if (TotalChapter7(quoteData) >= 7149)
return 5100;
else if (TotalChapter7(quoteData) >= 7099)
return 5050;
//...
else if (TotalChapter7(quoteData) >= 1199)
return 1100;
else if (TotalChapter7(quoteData) >= 1149)
return 1100;
else if (TotalChapter7(quoteData) >= 1099)
return 1050;
else if (TotalChapter7(quoteData) >= 1049)
return 1000;
else
return 0;
}
which has a recurring pattern which can be illustrated by the following Excel sheet:

……>>>>

Starting from the highest “Fee” (7499), the fee is dropping 50 on each statement. However, the return (or “Discounted Price”) stays the same for each 100 (two 50 drops in Fee), then drops 50 itself for one return (one 50 drop in Fee), and then repeats.
As you can see my method is pretty long (what I left out between 7049 and 1249). Is there something I can do to shorten this?
Thanks.
You guys are really overcomplicating this. Any approach along the lines of trying to solve this using integer arithmetic is a bad idea. Look how hard it is for a bunch of really smart people (we are all really smart, aren’t we?) to even get it right in the first place. It’s really hard to discover, it’s really hard to understand, it’s hard to get right, and it’s a bitch to maintain.
You need an approach that is easy to understand, and easy to maintain. Look at your original post, you have an English description of the rule.
The code practically writes itself: