lsibn
06-18-2001, 04:09 PM
Yeah, whatever. Here's the short version of the story:
I recently discovered somebody took out a $1000 bond in my name, and I was curious as to how long it would take to mature (really only curiosity- have to save it anyway). I looked at freshmeat.net for a compound interest calculator, and found one, but when I tried to download it (it was a C++ file) was told that it was being linked from another server which was not allowed. So I figured "It's simple math, it shouldn't be THAT hard to do..."
So I did. I wrote a version in C that did the trick, with 44 Lines of Code. Then I figured I could make it in C++, just for fun. So I did. I scrapped it, and re-wrote it in C++, and ran it through wc -l. What!? Now it's 97 LoC. I deleted the C version (didn't think to preserve it for posterity's sake...), but posted the C++ version somewhere ( http://utspl.cjb.net/cci.C should do the trick), and you can take a look at it. Is there anything I'm doing wrong there? I thought I had everything right...
But I'm perfectly willing to admit that I've screwed up a few things. Compiling is easy:
g++ cci.C -Wall -o cci
If you use -O0 on my box, the binary is 7084 bytes. If you use -O2, it's 8261.
In case the help message (when you run it) isn't obvious, it takes 3 arguments (no more, no less):
<The amount of money to start earning interest with.> <The rate of interest to compound> <The number of times interest will be compounded.>
So considering that it's so simple, and picky about when it works and doesn't, why is it so difficult to understand the code? I've GOTTA be doing something wrong...
Edit: BTW, there are a couple of unused variables because I wasn't sure how I was going to implement it. But they don't make the listing THAT much longer... I'd strip the variables, but I figured that (at this time) it's about as simple as it'll get, and it works.
[ 18 June 2001: Message edited by: lsibn ]
I recently discovered somebody took out a $1000 bond in my name, and I was curious as to how long it would take to mature (really only curiosity- have to save it anyway). I looked at freshmeat.net for a compound interest calculator, and found one, but when I tried to download it (it was a C++ file) was told that it was being linked from another server which was not allowed. So I figured "It's simple math, it shouldn't be THAT hard to do..."
So I did. I wrote a version in C that did the trick, with 44 Lines of Code. Then I figured I could make it in C++, just for fun. So I did. I scrapped it, and re-wrote it in C++, and ran it through wc -l. What!? Now it's 97 LoC. I deleted the C version (didn't think to preserve it for posterity's sake...), but posted the C++ version somewhere ( http://utspl.cjb.net/cci.C should do the trick), and you can take a look at it. Is there anything I'm doing wrong there? I thought I had everything right...
But I'm perfectly willing to admit that I've screwed up a few things. Compiling is easy:
g++ cci.C -Wall -o cci
If you use -O0 on my box, the binary is 7084 bytes. If you use -O2, it's 8261.
In case the help message (when you run it) isn't obvious, it takes 3 arguments (no more, no less):
<The amount of money to start earning interest with.> <The rate of interest to compound> <The number of times interest will be compounded.>
So considering that it's so simple, and picky about when it works and doesn't, why is it so difficult to understand the code? I've GOTTA be doing something wrong...
Edit: BTW, there are a couple of unused variables because I wasn't sure how I was going to implement it. But they don't make the listing THAT much longer... I'd strip the variables, but I figured that (at this time) it's about as simple as it'll get, and it works.
[ 18 June 2001: Message edited by: lsibn ]