A co-worker recently sent me a link about calculating checksums for tips (i.e. the tip you leave your server when paying for a meal at a restaurant). Without getting into the crux of the poster’s original argument (“thieving restaurant servers” – I don’t know how often this happens) I found the idea of creating checksums for tips intriguing.
That same night, at one of my family’s favorite restaurants, I decided to put the checksum into practice. However, I quickly realized that mentally calculating checksums for tips wasn’t all that fun :-).
So, what’s a software developer (with a Windows Mobile-enabled phone) to do? Develop an application, of course!
I decided to build a simple Windows Mobile application that supports the following features:
- Allows the entry of the total net amount (i.e. the amount on your bill)
- Allows you to select a level of service (e.g. Ok, Good, or Excellent) with an associated tip percentage.
- Allows you to select the tip calculation method (e.g. standard, checksum, or palindrome).
- Calculates the appropriate tip amount.
- Allows all default values to be modified.
Notice that I also implemented the “palindrome” method based on a comment on the original post.
The application has two screens. The first screen allows you to select the tip level and calculation method and also allows you to enter the net (bill) amount. As you enter the amount, the tip will be calculated based on the method you’ve selected.
The second screen (invoked by selecting the Preferences menu option) allows you to modify the application’s default values.
Granted this is a simple but it’s also my first mobile application so it’s been a good experience (plus it’s something that I’ll make use of). However, even though it’s simple, I’ve learned a lot about the differences in controls between the .NET Framework versions and how to use the Pocket PC emulators as well how mobile applications are deployed. There’s still lots to learn but we all have to start somewhere :-)
If you’re interested in the application, you can download the CAB file here. The application is compiled against the .NET Framework Compact Framework 2.0 which must be installed on your PDA and targets Windows Mobile 5.0.
I keep getting an “IndexOutOfRangeException” in CalculatePalindromeTip().
Am I doing something wrong?
Nope, you’re not doing anything wrong – there is just apparently a bug in the application.
Can you tell me what “service” percentage value you had selected as well as what amount you had entered when you got the error message?
I got the error message for any amount I entered. For example, it immediately came up after entering “2”, I could not even enter another digit.
I changed the percentages before doing so, to a more European 5/10/15/20 percent.
It might be due to the fact that I assume a decimal (‘.’) for a “cents” separator. By chance, do you use a comma (‘,’)? I’ll make the application a little friendlier for non-U.S. currency and re-post tomorrow evening.
that’s not it – I did not even get as far as entering anything other than the first digit before the runtime error occurred. Did you try setting the percentages to 5/10/15/20 and then simply entering “2”?
Checksum is broken for amount >$100. It looks like it is merely summing the ones and tens place digits and ignores anything higher.
EG: 115.36 @ 15% = 17.29 tip for a total of 132.65
“It looks like it is merely summing the ones and tens place digits and ignores anything higher.”
That is exactly how it is working. It bases the checksum purely on the “1’s” and “10’s” digits – anything higher is ignored.
In my opinion (and that’s all it is :-)) I think this approach makes reviewing the final totals easier since you only focus on two digits to the left and right of the decimal point.
Opinions?
“that’s not it – I did not even get as far as entering anything other than the first digit before the runtime error occurred. Did you try setting the percentages to 5/10/15/20 and then simply entering “2”?”
I did try that and it worked just fine. I’ll be giving the code a much closer look tonight to see what might be causing the issue.
Ok, I’ve posted an updated version of SafetyTip that should no longer have the “IndexOutOfRangeException”. It does appear that it was related to the difference in currency separator (decimal vs. comma) even though a decimal/comma hadn’t been entered.
Please give the new version a try and let me know how it works for you.
Yes, that fixed it. Thanks a lot!
Nice app. If you’re feeling bored an want another challenge, try http://forum.xda-developers.com/showthread.php?t=345127
so… whats a palindrome?
A palindrome is something that can be read in either direction. For example, the word “RADAR” is a palindrome. In the case of SafetyTip, using the palindrome option will generate a tip value that, when added to the cost of service, will provide a number that is a palindrome (e.g. $31.13) which makes scanning actual debit/credit charges easy to verify. If you see a restaurant charge for $12.21 then odds are it is valid. If you see something for 22.21 then you may want to take a closer look. Hope this helps.
actually i research about this mobile application issues because of some error but i got your article and its really good informative for me. so thank for sharing this kind of articles on this blog.